Search code examples
pythondjangodjango-urlsdjango-formwizard

How to call a "wizard view" with {% url %} statement in Django?


urls.py:

url(r'^signin_client$', views.signin_client, name='signin_client') # normal view,
url(r'^signup_owner$', SignupOwnerWizard.as_view()), # wizard view

In a 'normal view' case: <a href='{% url "myapp.views.signin_client" %}'> works.

But I can't figure how to do the same thing for my "wizard view". Of course, I don't want to hardcode the url.


Solution

  • Add name to the pattern:

    url(r'^signup_owner$', SignupOwnerWizard.as_view(), name='signup_owner'),
    

    And than use the name in {% url %} tag:

    <a href='{% url "signup_owner" %}'> 
    

    If you use namespaces you would need a namespace prefix:

    <a href='{% url "mynamespace:signup_owner" %}'>