Django Form Wizard

Sometimes, when dealing with large forms, we get the feeling of overwhelming complexity. Try putting yourself in the end user’s position, before you throw an endless number of fields onto a single page.

Form wizard is a simple solution that solves this complexity, and as a result leading to a better user experience.

As django developers we’re lucky to have a built-in form wizard application, although, I was bit surprised at how many developers either don’t use it (when they should) or know very little about it.

If you’re new to django form wizard, you can get started by visiting Django official docs.

Here are a few tips that I’ve rounded up over the course of a few projects for dealing with the form wizard.

Tip #1. When creating your wizard class, try to keep the clean. The official docs example doesn’t really follow this. Let’s fix it.

    ("step1", Form1),
    ("step2", Form2),
    "step1": "template/path/step1.html",
    "step2": "template/path/step2.html"

class MyFormWizard(SessionWizardView):
    # my awesome code

my_form_wizard_view = MyFormWizard.as_view(TRANSFER_FORMS)

url(r"^wizard/$", "my_form_wizard_view", name="my_form_wizard_view"),

As you see, we can build our view instance directly under wizard class, then assign it to our custom view name and use it in the thus keeping the nice and clean. No need for wizard related imports in!

Tip #2. Any time you upload the file in any step, Django will make a copy of it into the temporary path, but it won’t delete it for you, so you need to take care of it yourself, usually inside of the done method.

class MyFormWizard(SessionWizardView):
    location=os.path.join(settings.MEDIA_ROOT, 'temp', 'files')
    file_storage = FileSystemStorage(location)
    def done(self, form_list, **kwargs):
        upload_file = form_list[0].cleaned_data['my_file']
        # ...


Tip #3. Django wizard is a CBV, which means you can use mixins to easily extend its functionality. For this purpose I found django-braces very helpful.

from braces.views import UserPassesTestMixin

class MyFormWizard(UserPassesTestMixin, SessionWizardView):
    def test_func(self, user):
    return user.is_authenticated() and user.is_staffmember()


Tip #4. There are cases when creating more complicated and dynamic wizard flow that you may have the need of accessing submitted wizard data from outside views by hooking up ajax call. Here’s an example of how to access data and files from certain step form.

my_wizard_view = MyFormWizard.as_view([ ("step1", Form1), ])

def ajax_view(request, pk):
    storage = SessionStorage(
            location=os.path.join(settings.MEDIA_ROOT, 'temp', 'files')
    form = Form1(

    if form.is_valid(): 
        # we’re good, run my awesome code! 


Hopefully these few snippets will make your django development process easier and more fun. I hightly recommend for you to take a look at this great django addition to create better and more user friendly form wizards.

Django Form Wizard

Leave a Reply

Your email address will not be published. Required fields are marked *