[Django]-Custom Django FormWizard Steps with Templates

5👍

Hope you figured it out. For the sake of anyone who runs into this, this is how I solved this. I replaced {{ wizard.form }} with a for loop to manually render the inputs:

<form action="/contact/" method="post">{% csrf_token %}
<table>
{{ wizard.management_form }}
{% if wizard.form.forms %}
    {{ wizard.form.management_form }}
    {% for form in wizard.form.forms %}
        {{ form }}
    {% endfor %}
    {% else %}
        {% for field in wizard.form %}
            <label for="{{ field.id_for_label }}">{{ field.label }}</label>
            {{ field }}
            <span class="message">{{ field.errors }}</span>
        {% endfor %}
{% endif %}
</table>
{% if wizard.steps.prev %}
<button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">first step</button>
<button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">prev step</button>
{% endif %}
<input type="submit" value="submit"/>

You can create a template for each of your forms and then associate it to its corresponding form as described in the docs or if you want each form to use the same template, all you need to do is set your template_name attribute in your ContactWizard class:

class ContactWizard(SessionWizardView):
    template_name = "contact_form.html"

Leave a comment