0

I'm a beginner in Django.

In my template file, I have the following:

<select id="selectbox"></select>
<div id="containerdiv"></div>

Within the containerdiv, I can return a HttpResponse such as: <form> <!-- some more input elements here --> </form>

so now I will have a new form within the div. The content of the form will change depending on the value of selectbox. However, I also have {% csrf_token %} tag within the rendered HttpResponse which is not being rendered properly. Is this even the correct way to work with Django?

  • Maybe this is whatyou are looking for: https://www.geeksforgeeks.org/render-html-forms-get-post-in-django/ – Tms91 Oct 04 '20 at 18:58

1 Answers1

0

You could load as many forms in the page by the following method

def formPage(request):
    form1=FormA()
    form2=FormB()
    #as many as you want
    return render(request,"example.html",{"form1"=form1,"form2":form2})

Then call the forms in the HTML pages as per the name specified in the view, and use vanilla JS to render form as per choice selected in the choice box You can refer the following link: JS content manipulation

Harsh Vartak
  • 13
  • 1
  • 5