Hi, folks. I hope you’re all enjoying your weekend as best as possible.
I have a content submission form that I’m trying to build preview functionality for.
I don’t want to involve the server or database for this, but that’s probably irrelevant for this task here.
I’ve created the url →
urlpatterns = [
path('', views.index, name='index'),
path('search/', views.search, name='search'),
path('category/<str:category_name>/', views.category, name='category'),
path('contribute/', views.contribute, name='contribute'),
path('contribute/preview/', views.preview, name='preview'),
]
I’ve created the view →
def contribute(request):
template = 'searchnet/contribute.html'
context = {
"categories": CATEGORIES,
"tags": TAGS,
}
return render(request, template, context)
def preview(request):
template = 'searchnet/preview.html'
context = {}
return render(request, template, context)
The preview buttons html from contribute.html template is →
<input class="btn btn-outline my-2 button" type="button" name="preview" id="preview-button" data-bs-toggle="tooltip" title="View how your contetn will appear" data-bs-html="true" value="Preview" onclick="preview_submission()">
and finally the js function →
(I’ve tried many permutations of url strings here, not just the one you see here.)
function preview_submission(){
window.open("../{appname}/preview.html");
}
window.open("./preview/");
window.open("contribute/preview/");
This function is not internally on within script tags in the contribute.html file
I use vendor/app.js model and they are both located in static/{app_name}/js
The other caveat is that I want this to open in a new window. Obviously from the js function.
How do I load django views with javascript? I’ve not found anything in research that has worked.
I can’t load static files in js files. This isn’t an internal script on an html file where I could use the url tag.
the Page not found error even says it searched in the contribute/ path, but I’m still not gettting it right
So what is the best protocol for doing this? Thank you