Django Multiple Forms One Submit
I know this question has been answered before on this site, but for the life of me I can't figure it out. I want to submit two forms at once, with one submit button. Please, can an
Solution 1:
First, you have 2 forms defined in your views method form
and form2
, but you only add form
to your context.
Secondly, you don't put 2 forms in two different <form>
tags. You should put them in one so you could submit them at the same time.
Thirdly, not related, but you CANNOT name your views method list
. That's a django keyword for data structure list
, you could run into huge trouble if you try to use list
in other functions in your views file.
Edit:
You keep using variable {{ form.something }}
but you have 2 forms, so you just render the first form twice but completely ignored the second form. You should:
<form action="{% url "list" %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
{{ form2.as_p }}
<p><input type="submit" value="Upload"/></p>
</form>
ReEdit:
I'm not sure what caused the 403 to happen, but let's try replace render_to_response
with render
:
from django.shortcuts import render
def list(request):
# your code here
return render(request, 'list.html', {'documents': documents, 'form': form, 'form2': form2})
Post a Comment for "Django Multiple Forms One Submit"