0

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.

Sama
  • 55
  • 8
  • do you mean "to show an html code when you click on the URL link instead of routing you to the url"? – Abdelhamed Abdin Mar 30 '22 at 01:13
  • If you want to make changes your html without changing the URL, then you have to use "jquery" to display/hide the form. If you want to submit the form("new blog"), you can use ajax that sends form data to the view function without changing the URL. It would be better if you share your form and models related code. – B.Anup Mar 30 '22 at 03:49

0 Answers0