is it possible to open a html link form in a Django html include?
So, I don't want the link in the html to open in the browser address bar so that it can be seen. So I was wondering if you can somehow open it in the same template. But that didn't work for me, because the default data for the form is not taken.
As example:
in my .html file I have a URL
<li role="presentation"><a href="{% url 'create_exposition' blog.id %}">create new blog</a></li>
{% include "zed/create_exposition.html" with ...%}
This link in urls.py
re_path(r'^(?P<blog_id>[0-9]+)/create_exposition/$', views.create_exposition, name='create_exposition'),
and in the views.py
def create_exposition(request, blog_id):
form = ExpositionForm(request.POST or None)
blog= get_object_or_404(Blog, pk=blog_id)
if form.is_valid():
blogs_expositions = blog.exposition_set.all()
for s in blogs_expositions:
if s.identifikationsnummer == form.cleaned_data.get("idnumber"):
context = {
'blog': blog,
'form': form,
'error_message': 'You already added that exposition',
}
return render(request, 'zed/create_exposition.html', context)
exposition = form.save(commit=False)
exposition.blog= blog
exposition.save()
return render(request, 'zed/blog_detail.html', {'blog': blog})
context = {
'blog': blog,
'form': form,
}
return render(request, 'zed/create_exposition.html', context)
Yes, I know it is still the old away and no genericview. I am already retooling piece by piece.