[Answer]-Django – How to do a multi page form?

1👍

The Django Form Wizard is probably what you’re after. This will handle creating a session for you (using the SessionWizardView) and then present you at the end of the workflow with each of the completed forms, which you can then process, save to objects etc. as you see fit.

Create each of your forms for each step as such:

from django import forms

class BasicInfoForm(forms.Form):
    info_field_1 = forms.CharField(max_length=100)
    ...

class CheckoutForm(forms.Form):
    checkout_field_1 = forms.CharField(max_length=100)

...

Then create your view, which will process your forms once they’re all done. Be sure to redirect at the end.

from django.http import HttpResponseRedirect
from django.contrib.formtools.wizard.views import SessionWizardView

class SignupWizard(SessionWizardView):
    def done(self, form_list, **kwargs):
        (process each of your forms, which are contained in form list)
        return HttpResponseRedirect('/page-to-redirect-to-when-done/')

And then connect up the forms with the view in your urlconfig

urlpatterns = [
    url(r'^contact/$', ContactWizard.as_view([BasicInfoForm, CheckoutForm, ...]))
]

See the documentation for creating templates, how to process form_list etc.

Leave a comment