Django: Can class-based views accept two forms at a time?
Posted
by
Hooman
on Stack Overflow
See other posts from Stack Overflow
or by Hooman
Published on 2013-03-19T11:03:54Z
Indexed on
2014/06/03
9:25 UTC
Read the original article
Hit count: 247
If I have two forms:
class ContactForm(forms.Form):
name = forms.CharField()
message = forms.CharField(widget=forms.Textarea)
class SocialForm(forms.Form):
name = forms.CharField()
message = forms.CharField(widget=forms.Textarea)
and wanted to use a class based view, and send both forms to the template, is that even possible?
class TestView(FormView):
template_name = 'contact.html'
form_class = ContactForm
It seems the FormView can only accept one form at a time. In function based view though I can easily send two forms to my template and retrieve the content of both within the request.POST back.
variables = {'contact_form':contact_form, 'social_form':social_form }
return render(request, 'discussion.html', variables)
Is this a limitation of using class based view (generic views)?
Many Thanks
© Stack Overflow or respective owner