If you want every step of your wizard to have its own unique URL, use NamedUrlWizardView (or its session/cookie-backed variants NamedUrlSessionWizardView and NamedUrlCookieWizardView).
To implement this, you must:
- Use a subclass of
NamedUrlWizardView. - Provide a list of tuples to
as_view instead of a list of classes, where each tuple is (step_name, form_class). - Configure your
urls.py to capture the step name in the URL pattern. - Pass
url_name (required) and done_step_name (optional) to as_view.
url_name refers to the name of the URL pattern in your urls.py that handles the steps.
# urls.py
from django.urls import path, re_path
from myapp.forms import ContactForm1, ContactForm2
from myapp.views import ContactWizard
# Define steps with names
named_contact_forms = (
('contactdata', ContactForm1),
('leavemessage', ContactForm2),
)
# Configure the view with url_name and done_step_name
contact_wizard = ContactWizard.as_view(
named_contact_forms,
url_name='contact_step',
done_step_name='finished'
)
urlpatterns = [
# The regex must capture the 'step' keyword argument
re_path(r'^contact/(?P<step>.+)/$', contact_wizard, name='contact_step'),
# The base URL for the wizard
path('contact/', contact_wizard, name='contact'),
]