Sophie

Sophie

distrib > Fedora > 17 > x86_64 > by-pkgid > b6f82ea76d5134c5709ffcc9dc9e29c5 > files > 430

Django-doc-1.4.5-1.fc17.noarch.rpm


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Form wizard &mdash; Django 1.4.5 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '1.4.5',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.4.5 documentation" href="../../../index.html" />
    <link rel="up" title="django.contrib.formtools" href="index.html" />
    <link rel="next" title="GeoDjango" href="../gis/index.html" />
    <link rel="prev" title="Form preview" href="form-preview.html" />
 
<script type="text/javascript" src="../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>

  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 1.4.5 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="form-preview.html" title="Form preview">previous</a> 
     |
    <a href="../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="../gis/index.html" title="GeoDjango">next</a> &raquo;</div>
    </div>
    
    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-formtools-form-wizard">
            
  <div class="section" id="s-module-django.contrib.formtools.wizard.views">
<span id="s-form-wizard"></span><span id="module-django.contrib.formtools.wizard.views"></span><span id="form-wizard"></span><h1>Form wizard<a class="headerlink" href="#module-django.contrib.formtools.wizard.views" title="Permalink to this headline">¶</a></h1>
<p>Django comes with an optional &#8220;form wizard&#8221; application that splits
<a class="reference internal" href="../../../topics/forms/index.html"><em>forms</em></a> across multiple Web pages. It maintains
state in one of the backends so that the full server-side processing can be
delayed until the submission of the final form.</p>
<p>You might want to use this if you have a lengthy form that would be too
unwieldy for display on a single page. The first page might ask the user for
core information, the second page might ask for less important information,
etc.</p>
<p>The term &#8220;wizard&#8221;, in this context, is <a class="reference external" href="http://en.wikipedia.org/wiki/Wizard_%28software%29">explained on Wikipedia</a>.</p>
<div class="section" id="s-how-it-works">
<span id="how-it-works"></span><h2>How it works<a class="headerlink" href="#how-it-works" title="Permalink to this headline">¶</a></h2>
<p>Here&#8217;s the basic workflow for how a user would use a wizard:</p>
<ol class="arabic simple">
<li>The user visits the first page of the wizard, fills in the form and
submits it.</li>
<li>The server validates the data. If it&#8217;s invalid, the form is displayed
again, with error messages. If it&#8217;s valid, the server saves the current
state of the wizard in the backend and redirects to the next step.</li>
<li>Step 1 and 2 repeat, for every subsequent form in the wizard.</li>
<li>Once the user has submitted all the forms and all the data has been
validated, the wizard processes the data &#8211; saving it to the database,
sending an email, or whatever the application needs to do.</li>
</ol>
</div>
<div class="section" id="s-usage">
<span id="usage"></span><h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p>This application handles as much machinery for you as possible. Generally,
you just have to do these things:</p>
<ol class="arabic simple">
<li>Define a number of <a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> classes &#8211; one per
wizard page.</li>
<li>Create a <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> subclass that specifies what to do once
all of your forms have been submitted and validated. This also lets
you override some of the wizard&#8217;s behavior.</li>
<li>Create some templates that render the forms. You can define a single,
generic template to handle every one of the forms, or you can define a
specific template for each form.</li>
<li>Add <tt class="docutils literal"><span class="pre">django.contrib.formtools</span></tt> to your
<a class="reference internal" href="../../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> list in your settings file.</li>
<li>Point your URLconf at your <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> <tt class="xref py py-meth docutils literal"><span class="pre">as_view()</span></tt> method.</li>
</ol>
<div class="section" id="s-defining-form-classes">
<span id="defining-form-classes"></span><h3>Defining <tt class="docutils literal"><span class="pre">Form</span></tt> classes<a class="headerlink" href="#defining-form-classes" title="Permalink to this headline">¶</a></h3>
<p>The first step in creating a form wizard is to create the
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> classes.  These should be standard
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">django.forms.Form</span></tt></a> classes, covered in the <a class="reference internal" href="../../../topics/forms/index.html"><em>forms documentation</em></a>.  These classes can live anywhere in your codebase,
but convention is to put them in a file called <tt class="file docutils literal"><span class="pre">forms.py</span></tt> in your
application.</p>
<p>For example, let&#8217;s write a &#8220;contact form&#8221; wizard, where the first page&#8217;s form
collects the sender&#8217;s email address and subject, and the second page collects
the message itself. Here&#8217;s what the <tt class="file docutils literal"><span class="pre">forms.py</span></tt> might look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>

<span class="k">class</span> <span class="nc">ContactForm1</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">subject</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
    <span class="n">sender</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">EmailField</span><span class="p">()</span>

<span class="k">class</span> <span class="nc">ContactForm2</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">message</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">widget</span><span class="o">=</span><span class="n">forms</span><span class="o">.</span><span class="n">Textarea</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">In order to use <a class="reference internal" href="../../forms/fields.html#django.forms.FileField" title="django.forms.FileField"><tt class="xref py py-class docutils literal"><span class="pre">FileField</span></tt></a> in any form, see the
section <a class="reference internal" href="#wizard-files"><em>Handling files</em></a> below to learn more about
what to do.</p>
</div>
</div>
<div class="section" id="s-creating-a-wizardview-class">
<span id="creating-a-wizardview-class"></span><h3>Creating a <tt class="docutils literal"><span class="pre">WizardView</span></tt> class<a class="headerlink" href="#creating-a-wizardview-class" title="Permalink to this headline">¶</a></h3>
<p>The next step is to create a
<a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.formtools.wizard.views.WizardView</span></tt></a> subclass. You can
also use the <tt class="xref py py-class docutils literal"><span class="pre">SessionWizardView</span></tt> or <tt class="xref py py-class docutils literal"><span class="pre">CookieWizardView</span></tt> classes
which preselect the backend used for storing information during execution of the
wizard (as their names indicate, server-side sessions and browser cookies
respectively).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">To use the <tt class="xref py py-class docutils literal"><span class="pre">SessionWizardView</span></tt> follow the instructions
in the <a class="reference internal" href="../../../topics/http/sessions.html"><em>sessions documentation</em></a> on
how to enable sessions.</p>
</div>
<p>We will use the <tt class="xref py py-class docutils literal"><span class="pre">SessionWizardView</span></tt> in all examples but is is completely
fine to use the <tt class="xref py py-class docutils literal"><span class="pre">CookieWizardView</span></tt> instead. As with your
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> classes, this <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> class can live
anywhere in your codebase, but convention is to put it in <tt class="file docutils literal"><span class="pre">views.py</span></tt>.</p>
<p>The only requirement on this subclass is that it implement a
<a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView.done" title="django.contrib.formtools.wizard.views.WizardView.done"><tt class="xref py py-meth docutils literal"><span class="pre">done()</span></tt></a> method.</p>
<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.done">
<tt class="descclassname">WizardView.</tt><tt class="descname">done</tt>(<em>form_list</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.done" title="Permalink to this definition">¶</a></dt>
<dd><p>This method specifies what should happen when the data for <em>every</em> form is
submitted and validated. This method is passed a list of validated
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> instances.</p>
<p>In this simplistic example, rather than performing any database operation,
the method simply renders a template of the validated data:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render_to_response</span>
<span class="kn">from</span> <span class="nn">django.contrib.formtools.wizard.views</span> <span class="kn">import</span> <span class="n">SessionWizardView</span>

<span class="k">class</span> <span class="nc">ContactWizard</span><span class="p">(</span><span class="n">SessionWizardView</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">done</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form_list</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">render_to_response</span><span class="p">(</span><span class="s">&#39;done.html&#39;</span><span class="p">,</span> <span class="p">{</span>
            <span class="s">&#39;form_data&#39;</span><span class="p">:</span> <span class="p">[</span><span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span> <span class="k">for</span> <span class="n">form</span> <span class="ow">in</span> <span class="n">form_list</span><span class="p">],</span>
        <span class="p">})</span>
</pre></div>
</div>
<p>Note that this method will be called via <tt class="docutils literal"><span class="pre">POST</span></tt>, so it really ought to be a
good Web citizen and redirect after processing the data. Here&#8217;s another
example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">HttpResponseRedirect</span>
<span class="kn">from</span> <span class="nn">django.contrib.formtools.wizard.views</span> <span class="kn">import</span> <span class="n">SessionWizardView</span>

<span class="k">class</span> <span class="nc">ContactWizard</span><span class="p">(</span><span class="n">SessionWizardView</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">done</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form_list</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">do_something_with_the_form_data</span><span class="p">(</span><span class="n">form_list</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span><span class="s">&#39;/page-to-redirect-to-when-done/&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<p>See the section <a class="reference internal" href="#wizardview-advanced-methods"><em>Advanced WizardView methods</em></a>
below to learn about more <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> hooks.</p>
</div>
<div class="section" id="s-creating-templates-for-the-forms">
<span id="creating-templates-for-the-forms"></span><h3>Creating templates for the forms<a class="headerlink" href="#creating-templates-for-the-forms" title="Permalink to this headline">¶</a></h3>
<p>Next, you&#8217;ll need to create a template that renders the wizard&#8217;s forms. By
default, every form uses a template called
<tt class="file docutils literal"><span class="pre">formtools/wizard/wizard_form.html</span></tt>. You can change this template name
by overriding either the
<a class="reference internal" href="../../class-based-views.html#django.views.generic.base.TemplateResponseMixin.template_name" title="django.views.generic.base.TemplateResponseMixin.template_name"><tt class="xref py py-attr docutils literal"><span class="pre">template_name</span></tt></a> attribute
or the
<a class="reference internal" href="../../class-based-views.html#django.views.generic.base.TemplateResponseMixin.get_template_names" title="django.views.generic.base.TemplateResponseMixin.get_template_names"><tt class="xref py py-meth docutils literal"><span class="pre">get_template_names()</span></tt></a>
method, which are documented in the
<a class="reference internal" href="../../class-based-views.html#django.views.generic.base.TemplateResponseMixin" title="django.views.generic.base.TemplateResponseMixin"><tt class="xref py py-class docutils literal"><span class="pre">TemplateResponseMixin</span></tt></a> documentation.  The
latter one allows you to use a different template for each form (<a class="reference internal" href="#wizard-template-for-each-form"><em>see the
example below</em></a>).</p>
<p>This template expects a <tt class="docutils literal"><span class="pre">wizard</span></tt> object that has various items attached to
it:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">form</span></tt> &#8211; The <a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> or
<tt class="xref py py-class docutils literal"><span class="pre">BaseFormSet</span></tt> instance for the current step
(either empty or with errors).</li>
<li><tt class="docutils literal"><span class="pre">steps</span></tt> &#8211; A helper object to access the various steps related data:<ul>
<li><tt class="docutils literal"><span class="pre">step0</span></tt> &#8211; The current step (zero-based).</li>
<li><tt class="docutils literal"><span class="pre">step1</span></tt> &#8211; The current step (one-based).</li>
<li><tt class="docutils literal"><span class="pre">count</span></tt> &#8211; The total number of steps.</li>
<li><tt class="docutils literal"><span class="pre">first</span></tt> &#8211; The first step.</li>
<li><tt class="docutils literal"><span class="pre">last</span></tt> &#8211; The last step.</li>
<li><tt class="docutils literal"><span class="pre">current</span></tt> &#8211; The current (or first) step.</li>
<li><tt class="docutils literal"><span class="pre">next</span></tt> &#8211; The next step.</li>
<li><tt class="docutils literal"><span class="pre">prev</span></tt> &#8211; The previous step.</li>
<li><tt class="docutils literal"><span class="pre">index</span></tt> &#8211; The index of the current step.</li>
<li><tt class="docutils literal"><span class="pre">all</span></tt> &#8211; A list of all steps of the wizard.</li>
</ul>
</li>
</ul>
<p>You can supply additional context variables by using the
<a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView.get_context_data" title="django.contrib.formtools.wizard.views.WizardView.get_context_data"><tt class="xref py py-meth docutils literal"><span class="pre">get_context_data()</span></tt></a> method of your <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a>
subclass.</p>
<p>Here&#8217;s a full example template:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">extends</span> <span class="s2">&quot;base.html&quot;</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">load</span> <span class="nv">i18n</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">block</span> <span class="nv">head</span> <span class="cp">%}</span>
<span class="cp">{{</span> <span class="nv">wizard.form.media</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endblock</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">block</span> <span class="nv">content</span> <span class="cp">%}</span>
<span class="nt">&lt;p&gt;</span>Step <span class="cp">{{</span> <span class="nv">wizard.steps.step1</span> <span class="cp">}}</span> of <span class="cp">{{</span> <span class="nv">wizard.steps.count</span> <span class="cp">}}</span><span class="nt">&lt;/p&gt;</span>
<span class="nt">&lt;form</span> <span class="na">action=</span><span class="s">&quot;&quot;</span> <span class="na">method=</span><span class="s">&quot;post&quot;</span><span class="nt">&gt;</span><span class="cp">{%</span> <span class="k">csrf_token</span> <span class="cp">%}</span>
<span class="nt">&lt;table&gt;</span>
<span class="cp">{{</span> <span class="nv">wizard.management_form</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">if</span> <span class="nv">wizard.form.forms</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">wizard.form.management_form</span> <span class="cp">}}</span>
    <span class="cp">{%</span> <span class="k">for</span> <span class="nv">form</span> <span class="k">in</span> <span class="nv">wizard.form.forms</span> <span class="cp">%}</span>
        <span class="cp">{{</span> <span class="nv">form</span> <span class="cp">}}</span>
    <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">else</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">wizard.form</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
<span class="nt">&lt;/table&gt;</span>
<span class="cp">{%</span> <span class="k">if</span> <span class="nv">wizard.steps.prev</span> <span class="cp">%}</span>
<span class="nt">&lt;button</span> <span class="na">name=</span><span class="s">&quot;wizard_goto_step&quot;</span> <span class="na">type=</span><span class="s">&quot;submit&quot;</span> <span class="na">value=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">wizard.steps.first</span> <span class="cp">}}</span><span class="s">&quot;</span><span class="nt">&gt;</span><span class="cp">{%</span> <span class="k">trans</span> <span class="s2">&quot;first step&quot;</span> <span class="cp">%}</span><span class="nt">&lt;/button&gt;</span>
<span class="nt">&lt;button</span> <span class="na">name=</span><span class="s">&quot;wizard_goto_step&quot;</span> <span class="na">type=</span><span class="s">&quot;submit&quot;</span> <span class="na">value=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">wizard.steps.prev</span> <span class="cp">}}</span><span class="s">&quot;</span><span class="nt">&gt;</span><span class="cp">{%</span> <span class="k">trans</span> <span class="s2">&quot;prev step&quot;</span> <span class="cp">%}</span><span class="nt">&lt;/button&gt;</span>
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
<span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">&quot;submit&quot;</span> <span class="na">value=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">trans</span> <span class="s2">&quot;submit&quot;</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/form&gt;</span>
<span class="cp">{%</span> <span class="k">endblock</span> <span class="cp">%}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Note that <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">wizard.management_form</span> <span class="pre">}}</span></tt> <strong>must be used</strong> for
the wizard to work properly.</p>
</div>
</div>
<div class="section" id="s-hooking-the-wizard-into-a-urlconf">
<span id="s-wizard-urlconf"></span><span id="hooking-the-wizard-into-a-urlconf"></span><span id="wizard-urlconf"></span><h3>Hooking the wizard into a URLconf<a class="headerlink" href="#hooking-the-wizard-into-a-urlconf" title="Permalink to this headline">¶</a></h3>
<p>Finally, we need to specify which forms to use in the wizard, and then
deploy the new <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> object at an URL in the <tt class="docutils literal"><span class="pre">urls.py</span></tt>. The
wizard&#8217;s <tt class="xref py py-meth docutils literal"><span class="pre">as_view()</span></tt> method takes a list of your
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> classes as an argument during instantiation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">patterns</span>

<span class="kn">from</span> <span class="nn">myapp.forms</span> <span class="kn">import</span> <span class="n">ContactForm1</span><span class="p">,</span> <span class="n">ContactForm2</span>
<span class="kn">from</span> <span class="nn">myapp.views</span> <span class="kn">import</span> <span class="n">ContactWizard</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^contact/$&#39;</span><span class="p">,</span> <span class="n">ContactWizard</span><span class="o">.</span><span class="n">as_view</span><span class="p">([</span><span class="n">ContactForm1</span><span class="p">,</span> <span class="n">ContactForm2</span><span class="p">])),</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-using-a-different-template-for-each-form">
<span id="s-wizard-template-for-each-form"></span><span id="using-a-different-template-for-each-form"></span><span id="wizard-template-for-each-form"></span><h3>Using a different template for each form<a class="headerlink" href="#using-a-different-template-for-each-form" title="Permalink to this headline">¶</a></h3>
<p>As mentioned above, you may specify a different template for each form.
Consider an example using a form wizard to implement a multi-step checkout
process for an online store. In the first step, the user specifies a billing
and shipping address. In the second step, the user chooses payment type. If
they chose to pay by credit card, they will enter credit card information in
the next step. In the final step, they will confirm the purchase.</p>
<p>Here&#8217;s what the view code might look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">HttpResponseRedirect</span>
<span class="kn">from</span> <span class="nn">django.contrib.formtools.wizard.views</span> <span class="kn">import</span> <span class="n">SessionWizardView</span>

<span class="n">FORMS</span> <span class="o">=</span> <span class="p">[(</span><span class="s">&quot;address&quot;</span><span class="p">,</span> <span class="n">myapp</span><span class="o">.</span><span class="n">forms</span><span class="o">.</span><span class="n">AddressForm</span><span class="p">),</span>
         <span class="p">(</span><span class="s">&quot;paytype&quot;</span><span class="p">,</span> <span class="n">myapp</span><span class="o">.</span><span class="n">forms</span><span class="o">.</span><span class="n">PaymentChoiceForm</span><span class="p">),</span>
         <span class="p">(</span><span class="s">&quot;cc&quot;</span><span class="p">,</span> <span class="n">myapp</span><span class="o">.</span><span class="n">forms</span><span class="o">.</span><span class="n">CreditCardForm</span><span class="p">),</span>
         <span class="p">(</span><span class="s">&quot;confirmation&quot;</span><span class="p">,</span> <span class="n">myapp</span><span class="o">.</span><span class="n">forms</span><span class="o">.</span><span class="n">OrderForm</span><span class="p">)]</span>

<span class="n">TEMPLATES</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;address&quot;</span><span class="p">:</span> <span class="s">&quot;checkout/billingaddress.html&quot;</span><span class="p">,</span>
             <span class="s">&quot;paytype&quot;</span><span class="p">:</span> <span class="s">&quot;checkout/paymentmethod.html&quot;</span><span class="p">,</span>
             <span class="s">&quot;cc&quot;</span><span class="p">:</span> <span class="s">&quot;checkout/creditcard.html&quot;</span><span class="p">,</span>
             <span class="s">&quot;confirmation&quot;</span><span class="p">:</span> <span class="s">&quot;checkout/confirmation.html&quot;</span><span class="p">}</span>

<span class="k">def</span> <span class="nf">pay_by_credit_card</span><span class="p">(</span><span class="n">wizard</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Return true if user opts to pay by credit card&quot;&quot;&quot;</span>
    <span class="c"># Get cleaned data from payment step</span>
    <span class="n">cleaned_data</span> <span class="o">=</span> <span class="n">wizard</span><span class="o">.</span><span class="n">get_cleaned_data_for_step</span><span class="p">(</span><span class="s">&#39;paytype&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="p">{</span><span class="s">&#39;method&#39;</span><span class="p">:</span> <span class="s">&#39;none&#39;</span><span class="p">}</span>
    <span class="c"># Return true if the user selected credit card</span>
    <span class="k">return</span> <span class="n">cleaned_data</span><span class="p">[</span><span class="s">&#39;method&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;cc&#39;</span>


<span class="k">class</span> <span class="nc">OrderWizard</span><span class="p">(</span><span class="n">SessionWizardView</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">get_template_names</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">TEMPLATES</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">steps</span><span class="o">.</span><span class="n">current</span><span class="p">]]</span>

    <span class="k">def</span> <span class="nf">done</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form_list</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">do_something_with_the_form_data</span><span class="p">(</span><span class="n">form_list</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span><span class="s">&#39;/page-to-redirect-to-when-done/&#39;</span><span class="p">)</span>
        <span class="o">...</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">urls.py</span></tt> file would contain something like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^checkout/$&#39;</span><span class="p">,</span> <span class="n">OrderWizard</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span><span class="n">FORMS</span><span class="p">,</span> <span class="n">condition_dict</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;cc&#39;</span><span class="p">:</span> <span class="n">pay_by_credit_card</span><span class="p">})),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Note that the <tt class="docutils literal"><span class="pre">OrderWizard</span></tt> object is initialized with a list of pairs.
The first element in the pair is a string that corresponds to the name of the
step and the second is the form class.</p>
<p>In this example, the
<a class="reference internal" href="../../class-based-views.html#django.views.generic.base.TemplateResponseMixin.get_template_names" title="django.views.generic.base.TemplateResponseMixin.get_template_names"><tt class="xref py py-meth docutils literal"><span class="pre">get_template_names()</span></tt></a>
method returns a list containing a single template, which is selected based on
the name of the current step.</p>
</div>
</div>
<div class="section" id="s-advanced-wizardview-methods">
<span id="s-wizardview-advanced-methods"></span><span id="advanced-wizardview-methods"></span><span id="wizardview-advanced-methods"></span><h2>Advanced <tt class="docutils literal"><span class="pre">WizardView</span></tt> methods<a class="headerlink" href="#advanced-wizardview-methods" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.contrib.formtools.wizard.views.WizardView">
<em class="property">class </em><tt class="descname">WizardView</tt><a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView" title="Permalink to this definition">¶</a></dt>
<dd><p>Aside from the <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView.done" title="django.contrib.formtools.wizard.views.WizardView.done"><tt class="xref py py-meth docutils literal"><span class="pre">done()</span></tt></a> method, <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> offers a few
advanced method hooks that let you customize how your wizard works.</p>
<p>Some of these methods take an argument <tt class="docutils literal"><span class="pre">step</span></tt>, which is a zero-based
counter as string representing the current step of the wizard. (E.g., the
first form is <tt class="docutils literal"><span class="pre">'0'</span></tt> and the second form is <tt class="docutils literal"><span class="pre">'1'</span></tt>)</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.get_form_prefix">
<tt class="descclassname">WizardView.</tt><tt class="descname">get_form_prefix</tt>(<em>step</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.get_form_prefix" title="Permalink to this definition">¶</a></dt>
<dd><p>Given the step, returns a form prefix to use. By default, this simply uses
the step itself. For more, see the <a class="reference internal" href="../../forms/api.html#form-prefix"><em>form prefix documentation</em></a>.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.get_form_initial">
<tt class="descclassname">WizardView.</tt><tt class="descname">get_form_initial</tt>(<em>step</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.get_form_initial" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a dictionary which will be passed as the
<a class="reference internal" href="../../forms/api.html#django.forms.Form.initial" title="django.forms.Form.initial"><tt class="xref py py-attr docutils literal"><span class="pre">initial</span></tt></a> argument when instantiating the Form
instance for step <tt class="docutils literal"><span class="pre">step</span></tt>. If no initial data was provided while
initializing the form wizard, an empty dictionary should be returned.</p>
<p>The default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_form_initial</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">step</span><span class="p">):</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">initial_dict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">step</span><span class="p">,</span> <span class="p">{})</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.get_form_kwargs">
<tt class="descclassname">WizardView.</tt><tt class="descname">get_form_kwargs</tt>(<em>step</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.get_form_kwargs" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a dictionary which will be used as the keyword arguments when
instantiating the form instance on given <tt class="docutils literal"><span class="pre">step</span></tt>.</p>
<p>The default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_form_kwargs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">step</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">{}</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.get_form_instance">
<tt class="descclassname">WizardView.</tt><tt class="descname">get_form_instance</tt>(<em>step</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.get_form_instance" title="Permalink to this definition">¶</a></dt>
<dd><p>This method will be called only if a <a class="reference internal" href="../../../topics/forms/modelforms.html#django.forms.ModelForm" title="django.forms.ModelForm"><tt class="xref py py-class docutils literal"><span class="pre">ModelForm</span></tt></a> is
used as the form for step <tt class="docutils literal"><span class="pre">step</span></tt>.</p>
<p>Returns an <a class="reference internal" href="../../models/instances.html#django.db.models.Model" title="django.db.models.Model"><tt class="xref py py-class docutils literal"><span class="pre">Model</span></tt></a> object which will be passed as
the <tt class="xref py py-attr docutils literal"><span class="pre">instance</span></tt> argument when instantiating the
ModelForm for step <tt class="docutils literal"><span class="pre">step</span></tt>.  If no instance object was provided while
initializing the form wizard, <tt class="docutils literal"><span class="pre">None</span></tt> will be returned.</p>
<p>The default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_form_instance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">step</span><span class="p">):</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">instance_dict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">step</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.get_context_data">
<tt class="descclassname">WizardView.</tt><tt class="descname">get_context_data</tt>(<em>form</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.get_context_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the template context for a step. You can overwrite this method
to add more data for all or some steps. This method returns a dictionary
containing the rendered form step.</p>
<p>The default template context variables are:</p>
<ul class="simple">
<li>Any extra data the storage backend has stored</li>
<li><tt class="docutils literal"><span class="pre">form</span></tt> &#8211; form instance of the current step</li>
<li><tt class="docutils literal"><span class="pre">wizard</span></tt> &#8211; the wizard instance itself</li>
</ul>
<p>Example to add extra variables for a specific step:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="n">context</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyWizard</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="n">form</span><span class="o">=</span><span class="n">form</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">steps</span><span class="o">.</span><span class="n">current</span> <span class="o">==</span> <span class="s">&#39;my_step_name&#39;</span><span class="p">:</span>
        <span class="n">context</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s">&#39;another_var&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>
    <span class="k">return</span> <span class="n">context</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.get_prefix">
<tt class="descclassname">WizardView.</tt><tt class="descname">get_prefix</tt>(<em>*args</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.get_prefix" title="Permalink to this definition">¶</a></dt>
<dd><p>This method returns a prefix for use by the storage backends. Backends use
the prefix as a mechanism to allow data to be stored separately for each
wizard. This allows wizards to store their data in a single backend
without overwriting each other.</p>
<p>You can change this method to make the wizard data prefix more unique to,
e.g. have multiple instances of one wizard in one session.</p>
<p>Default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_prefix</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="c"># use the lowercase underscore version of the class name</span>
    <span class="k">return</span> <span class="n">normalize_name</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.get_form">
<tt class="descclassname">WizardView.</tt><tt class="descname">get_form</tt>(<em>step=None</em>, <em>data=None</em>, <em>files=None</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.get_form" title="Permalink to this definition">¶</a></dt>
<dd><p>This method constructs the form for a given <tt class="docutils literal"><span class="pre">step</span></tt>. If no <tt class="docutils literal"><span class="pre">step</span></tt> is
defined, the current step will be determined automatically.
The method gets three arguments:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">step</span></tt> &#8211; The step for which the form instance should be generated.</li>
<li><tt class="docutils literal"><span class="pre">data</span></tt> &#8211; Gets passed to the form&#8217;s data argument</li>
<li><tt class="docutils literal"><span class="pre">files</span></tt> &#8211; Gets passed to the form&#8217;s files argument</li>
</ul>
<p>You can override this method to add extra arguments to the form instance.</p>
<p>Example code to add a user attribute to the form on step 2:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_form</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">step</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="n">form</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyWizard</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_form</span><span class="p">(</span><span class="n">step</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">files</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">step</span> <span class="o">==</span> <span class="s">&#39;1&#39;</span><span class="p">:</span>
        <span class="n">form</span><span class="o">.</span><span class="n">user</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">user</span>
    <span class="k">return</span> <span class="n">form</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.process_step">
<tt class="descclassname">WizardView.</tt><tt class="descname">process_step</tt>(<em>form</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.process_step" title="Permalink to this definition">¶</a></dt>
<dd><p>Hook for modifying the wizard&#8217;s internal state, given a fully validated
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> object. The Form is guaranteed to have clean,
valid data.</p>
<p>This method gives you a way to post-process the form data before the data
gets stored within the storage backend. By default it just returns the
<tt class="docutils literal"><span class="pre">form.data</span></tt> dictionary. You should not manipulate the data here but you
can use it to do some extra work if needed (e.g. set storage extra data).</p>
<p>Note that this method is called every time a page is rendered for <em>all</em>
submitted steps.</p>
<p>The default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">process_step</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form</span><span class="p">):</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_form_step_data</span><span class="p">(</span><span class="n">form</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.process_step_files">
<tt class="descclassname">WizardView.</tt><tt class="descname">process_step_files</tt>(<em>form</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.process_step_files" title="Permalink to this definition">¶</a></dt>
<dd><p>This method gives you a way to post-process the form files before the
files gets stored within the storage backend. By default it just returns
the <tt class="docutils literal"><span class="pre">form.files</span></tt> dictionary. You should not manipulate the data here
but you can use it to do some extra work if needed (e.g. set storage
extra data).</p>
<p>Default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">process_step_files</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form</span><span class="p">):</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_form_step_files</span><span class="p">(</span><span class="n">form</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.render_revalidation_failure">
<tt class="descclassname">WizardView.</tt><tt class="descname">render_revalidation_failure</tt>(<em>step</em>, <em>form</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.render_revalidation_failure" title="Permalink to this definition">¶</a></dt>
<dd><p>When the wizard thinks all steps have passed it revalidates all forms with
the data from the backend storage.</p>
<p>If any of the forms don&#8217;t validate correctly, this method gets called.
This method expects two arguments, <tt class="docutils literal"><span class="pre">step</span></tt> and <tt class="docutils literal"><span class="pre">form</span></tt>.</p>
<p>The default implementation resets the current step to the first failing
form and redirects the user to the invalid form.</p>
<p>Default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">render_revalidation_failure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="n">form</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">storage</span><span class="o">.</span><span class="n">current_step</span> <span class="o">=</span> <span class="n">step</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">form</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.get_form_step_data">
<tt class="descclassname">WizardView.</tt><tt class="descname">get_form_step_data</tt>(<em>form</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.get_form_step_data" title="Permalink to this definition">¶</a></dt>
<dd><p>This method fetches the data from the <tt class="docutils literal"><span class="pre">form</span></tt> Form instance and returns the
dictionary. You can use this method to manipulate the values before the data
gets stored in the storage backend.</p>
<p>Default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_form_step_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">form</span><span class="o">.</span><span class="n">data</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.get_form_step_files">
<tt class="descclassname">WizardView.</tt><tt class="descname">get_form_step_files</tt>(<em>form</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.get_form_step_files" title="Permalink to this definition">¶</a></dt>
<dd><p>This method returns the form files. You can use this method to manipulate
the files before the data gets stored in the storage backend.</p>
<p>Default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_form_step_files</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">form</span><span class="o">.</span><span class="n">files</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.views.WizardView.render">
<tt class="descclassname">WizardView.</tt><tt class="descname">render</tt>(<em>form</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.render" title="Permalink to this definition">¶</a></dt>
<dd><p>This method gets called after the GET or POST request has been handled. You
can hook in this method to, e.g. change the type of HTTP response.</p>
<p>Default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">render</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="n">form</span> <span class="o">=</span> <span class="n">form</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_form</span><span class="p">()</span>
    <span class="n">context</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="n">form</span><span class="o">=</span><span class="n">form</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">render_to_response</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="s-providing-initial-data-for-the-forms">
<span id="providing-initial-data-for-the-forms"></span><h2>Providing initial data for the forms<a class="headerlink" href="#providing-initial-data-for-the-forms" title="Permalink to this headline">¶</a></h2>
<dl class="attribute">
<dt id="django.contrib.formtools.wizard.views.WizardView.initial_dict">
<tt class="descclassname">WizardView.</tt><tt class="descname">initial_dict</tt><a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.initial_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>Initial data for a wizard&#8217;s <a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> objects can be
provided using the optional <tt class="xref py py-attr docutils literal"><span class="pre">initial_dict</span></tt> keyword argument.
This argument should be a dictionary mapping the steps to dictionaries
containing the initial data for each step. The dictionary of initial data
will be passed along to the constructor of the step&#8217;s
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">myapp.forms</span> <span class="kn">import</span> <span class="n">ContactForm1</span><span class="p">,</span> <span class="n">ContactForm2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">myapp.views</span> <span class="kn">import</span> <span class="n">ContactWizard</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">initial</span> <span class="o">=</span> <span class="p">{</span>
<span class="gp">... </span>    <span class="s">&#39;0&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s">&#39;subject&#39;</span><span class="p">:</span> <span class="s">&#39;Hello&#39;</span><span class="p">,</span> <span class="s">&#39;sender&#39;</span><span class="p">:</span> <span class="s">&#39;user@example.com&#39;</span><span class="p">},</span>
<span class="gp">... </span>    <span class="s">&#39;1&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s">&#39;message&#39;</span><span class="p">:</span> <span class="s">&#39;Hi there!&#39;</span><span class="p">}</span>
<span class="gp">... </span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">wiz</span> <span class="o">=</span> <span class="n">ContactWizard</span><span class="o">.</span><span class="n">as_view</span><span class="p">([</span><span class="n">ContactForm1</span><span class="p">,</span> <span class="n">ContactForm2</span><span class="p">],</span> <span class="n">initial_dict</span><span class="o">=</span><span class="n">initial</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">form1</span> <span class="o">=</span> <span class="n">wiz</span><span class="o">.</span><span class="n">get_form</span><span class="p">(</span><span class="s">&#39;0&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">form2</span> <span class="o">=</span> <span class="n">wiz</span><span class="o">.</span><span class="n">get_form</span><span class="p">(</span><span class="s">&#39;1&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">form1</span><span class="o">.</span><span class="n">initial</span>
<span class="go">{&#39;sender&#39;: &#39;user@example.com&#39;, &#39;subject&#39;: &#39;Hello&#39;}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">form2</span><span class="o">.</span><span class="n">initial</span>
<span class="go">{&#39;message&#39;: &#39;Hi there!&#39;}</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">initial_dict</span></tt> can also take a list of dictionaries for a specific
step if the step is a <tt class="docutils literal"><span class="pre">FormSet</span></tt>.</p>
</dd></dl>

</div>
<div class="section" id="s-handling-files">
<span id="s-wizard-files"></span><span id="handling-files"></span><span id="wizard-files"></span><h2>Handling files<a class="headerlink" href="#handling-files" title="Permalink to this headline">¶</a></h2>
<p>To handle <a class="reference internal" href="../../forms/fields.html#django.forms.FileField" title="django.forms.FileField"><tt class="xref py py-class docutils literal"><span class="pre">FileField</span></tt></a> within any step form of the wizard,
you have to add a <tt class="xref py py-attr docutils literal"><span class="pre">file_storage</span></tt> to your <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> subclass.</p>
<p>This storage will temporarily store the uploaded files for the wizard. The
<tt class="xref py py-attr docutils literal"><span class="pre">file_storage</span></tt> attribute should be a
<a class="reference internal" href="../../files/storage.html#django.core.files.storage.Storage" title="django.core.files.storage.Storage"><tt class="xref py py-class docutils literal"><span class="pre">Storage</span></tt></a> subclass.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Please remember to take care of removing old files as the
<a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> won&#8217;t remove any files, whether the wizard gets
finished correctly or not.</p>
</div>
</div>
<div class="section" id="s-conditionally-view-skip-specific-steps">
<span id="conditionally-view-skip-specific-steps"></span><h2>Conditionally view/skip specific steps<a class="headerlink" href="#conditionally-view-skip-specific-steps" title="Permalink to this headline">¶</a></h2>
<dl class="attribute">
<dt id="django.contrib.formtools.wizard.views.WizardView.condition_dict">
<tt class="descclassname">WizardView.</tt><tt class="descname">condition_dict</tt><a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.condition_dict" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <tt class="xref py py-meth docutils literal"><span class="pre">as_view()</span></tt> method accepts a <tt class="docutils literal"><span class="pre">condition_dict</span></tt> argument.
You can pass a dictionary of boolean values or callables. The key should match
the steps names (e.g. &#8216;0&#8217;, &#8216;1&#8217;).</p>
<p>If the value of a specific step is callable it will be called with the
<a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> instance as the only argument. If the return value is true,
the step&#8217;s form will be used.</p>
<p>This example provides a contact form including a condition. The condition is
used to show a message form only if a checkbox in the first step was checked.</p>
<p>The steps are defined in a <tt class="docutils literal"><span class="pre">forms.py</span></tt> file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>

<span class="k">class</span> <span class="nc">ContactForm1</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">subject</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
    <span class="n">sender</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">EmailField</span><span class="p">()</span>
    <span class="n">leave_message</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">BooleanField</span><span class="p">(</span><span class="n">required</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">ContactForm2</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">message</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">widget</span><span class="o">=</span><span class="n">forms</span><span class="o">.</span><span class="n">Textarea</span><span class="p">)</span>
</pre></div>
</div>
<p>We define our wizard in a <tt class="docutils literal"><span class="pre">views.py</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render_to_response</span>
<span class="kn">from</span> <span class="nn">django.contrib.formtools.wizard.views</span> <span class="kn">import</span> <span class="n">SessionWizardView</span>

<span class="k">def</span> <span class="nf">show_message_form_condition</span><span class="p">(</span><span class="n">wizard</span><span class="p">):</span>
    <span class="c"># try to get the cleaned data of step 1</span>
    <span class="n">cleaned_data</span> <span class="o">=</span> <span class="n">wizard</span><span class="o">.</span><span class="n">get_cleaned_data_for_step</span><span class="p">(</span><span class="s">&#39;0&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="p">{}</span>
    <span class="c"># check if the field ``leave_message`` was checked.</span>
    <span class="k">return</span> <span class="n">cleaned_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;leave_message&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">ContactWizard</span><span class="p">(</span><span class="n">SessionWizardView</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">done</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form_list</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">render_to_response</span><span class="p">(</span><span class="s">&#39;done.html&#39;</span><span class="p">,</span> <span class="p">{</span>
            <span class="s">&#39;form_data&#39;</span><span class="p">:</span> <span class="p">[</span><span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span> <span class="k">for</span> <span class="n">form</span> <span class="ow">in</span> <span class="n">form_list</span><span class="p">],</span>
        <span class="p">})</span>
</pre></div>
</div>
<p>We need to add the <tt class="docutils literal"><span class="pre">ContactWizard</span></tt> to our <tt class="docutils literal"><span class="pre">urls.py</span></tt> file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">patterns</span>

<span class="kn">from</span> <span class="nn">myapp.forms</span> <span class="kn">import</span> <span class="n">ContactForm1</span><span class="p">,</span> <span class="n">ContactForm2</span>
<span class="kn">from</span> <span class="nn">myapp.views</span> <span class="kn">import</span> <span class="n">ContactWizard</span><span class="p">,</span> <span class="n">show_message_form_condition</span>

<span class="n">contact_forms</span> <span class="o">=</span> <span class="p">[</span><span class="n">ContactForm1</span><span class="p">,</span> <span class="n">ContactForm2</span><span class="p">]</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^contact/$&#39;</span><span class="p">,</span> <span class="n">ContactWizard</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span><span class="n">contact_forms</span><span class="p">,</span>
        <span class="n">condition_dict</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;1&#39;</span><span class="p">:</span> <span class="n">show_message_form_condition</span><span class="p">}</span>
    <span class="p">)),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>As you can see, we defined a <tt class="docutils literal"><span class="pre">show_message_form_condition</span></tt> next to our
<a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> subclass and added a <tt class="docutils literal"><span class="pre">condition_dict</span></tt> argument to the
<tt class="xref py py-meth docutils literal"><span class="pre">as_view()</span></tt> method. The key refers to the second wizard step
(because of the zero based step index).</p>
</div>
<div class="section" id="s-how-to-work-with-modelform-and-modelformset">
<span id="how-to-work-with-modelform-and-modelformset"></span><h2>How to work with ModelForm and ModelFormSet<a class="headerlink" href="#how-to-work-with-modelform-and-modelformset" title="Permalink to this headline">¶</a></h2>
<dl class="attribute">
<dt id="django.contrib.formtools.wizard.views.WizardView.instance_dict">
<tt class="descclassname">WizardView.</tt><tt class="descname">instance_dict</tt><a class="headerlink" href="#django.contrib.formtools.wizard.views.WizardView.instance_dict" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>WizardView supports <a class="reference internal" href="../../../topics/forms/modelforms.html"><em>ModelForms</em></a> and
<a class="reference internal" href="../../../topics/forms/modelforms.html#model-formsets"><em>ModelFormSets</em></a>. Additionally to
<a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView.initial_dict" title="django.contrib.formtools.wizard.views.WizardView.initial_dict"><tt class="xref py py-attr docutils literal"><span class="pre">initial_dict</span></tt></a>, the <tt class="xref py py-meth docutils literal"><span class="pre">as_view()</span></tt> method takes
an <tt class="docutils literal"><span class="pre">instance_dict</span></tt> argument that should contain instances of <tt class="docutils literal"><span class="pre">ModelForm</span></tt> and
<tt class="docutils literal"><span class="pre">ModelFormSet</span></tt>.  Similarly to <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView.initial_dict" title="django.contrib.formtools.wizard.views.WizardView.initial_dict"><tt class="xref py py-attr docutils literal"><span class="pre">initial_dict</span></tt></a>, these
dictionary key values should be equal to the step number in the form list.</p>
</div>
<div class="section" id="s-usage-of-namedurlwizardview">
<span id="usage-of-namedurlwizardview"></span><h2>Usage of <tt class="docutils literal"><span class="pre">NamedUrlWizardView</span></tt><a class="headerlink" href="#usage-of-namedurlwizardview" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.contrib.formtools.wizard.views.NamedUrlWizardView">
<em class="property">class </em><tt class="descname">NamedUrlWizardView</tt><a class="headerlink" href="#django.contrib.formtools.wizard.views.NamedUrlWizardView" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>There is a <a class="reference internal" href="#django.contrib.formtools.wizard.views.WizardView" title="django.contrib.formtools.wizard.views.WizardView"><tt class="xref py py-class docutils literal"><span class="pre">WizardView</span></tt></a> subclass which adds named-urls support to the wizard.
By doing this, you can have single urls for every step.</p>
<p>To use the named urls, you have to change the <tt class="docutils literal"><span class="pre">urls.py</span></tt>.</p>
<p>Below you will see an example of a contact wizard with two steps, step 1 with
&#8220;contactdata&#8221; as its name and step 2 with &#8220;leavemessage&#8221; as its name.</p>
<p>Additionally you have to pass two more arguments to the
<tt class="xref py py-meth docutils literal"><span class="pre">as_view()</span></tt> method:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">url_name</span></tt> &#8211; the name of the url (as provided in the urls.py)</li>
<li><tt class="docutils literal"><span class="pre">done_step_name</span></tt> &#8211; the name in the url for the done step</li>
</ul>
<p>Example code for the changed <tt class="docutils literal"><span class="pre">urls.py</span></tt> file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">url</span><span class="p">,</span> <span class="n">patterns</span>

<span class="kn">from</span> <span class="nn">myapp.forms</span> <span class="kn">import</span> <span class="n">ContactForm1</span><span class="p">,</span> <span class="n">ContactForm2</span>
<span class="kn">from</span> <span class="nn">myapp.views</span> <span class="kn">import</span> <span class="n">ContactWizard</span>

<span class="n">named_contact_forms</span> <span class="o">=</span> <span class="p">(</span>
    <span class="p">(</span><span class="s">&#39;contactdata&#39;</span><span class="p">,</span> <span class="n">ContactForm1</span><span class="p">),</span>
    <span class="p">(</span><span class="s">&#39;leavemessage&#39;</span><span class="p">,</span> <span class="n">ContactForm2</span><span class="p">),</span>
<span class="p">)</span>

<span class="n">contact_wizard</span> <span class="o">=</span> <span class="n">ContactWizard</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span><span class="n">named_contact_forms</span><span class="p">,</span>
    <span class="n">url_name</span><span class="o">=</span><span class="s">&#39;contact_step&#39;</span><span class="p">,</span> <span class="n">done_step_name</span><span class="o">=</span><span class="s">&#39;finished&#39;</span><span class="p">)</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^contact/(?P&lt;step&gt;.+)/$&#39;</span><span class="p">,</span> <span class="n">contact_wizard</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;contact_step&#39;</span><span class="p">),</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^contact/$&#39;</span><span class="p">,</span> <span class="n">contact_wizard</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;contact&#39;</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-advanced-namedurlwizardview-methods">
<span id="advanced-namedurlwizardview-methods"></span><h2>Advanced <tt class="docutils literal"><span class="pre">NamedUrlWizardView</span></tt> methods<a class="headerlink" href="#advanced-namedurlwizardview-methods" title="Permalink to this headline">¶</a></h2>
<dl class="method">
<dt id="django.contrib.formtools.wizard.views.NamedUrlWizardView.get_step_url">
<tt class="descclassname">NamedUrlWizardView.</tt><tt class="descname">get_step_url</tt>(<em>step</em>)<a class="headerlink" href="#django.contrib.formtools.wizard.views.NamedUrlWizardView.get_step_url" title="Permalink to this definition">¶</a></dt>
<dd><p>This method returns the URL for a specific step.</p>
<p>Default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_step_url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">step</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">reverse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">url_name</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;step&#39;</span><span class="p">:</span> <span class="n">step</span><span class="p">})</span>
</pre></div>
</div>
</dd></dl>

</div>
</div>


          </div>         
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Form wizard</a><ul>
<li><a class="reference internal" href="#how-it-works">How it works</a></li>
<li><a class="reference internal" href="#usage">Usage</a><ul>
<li><a class="reference internal" href="#defining-form-classes">Defining <tt class="docutils literal"><span class="pre">Form</span></tt> classes</a></li>
<li><a class="reference internal" href="#creating-a-wizardview-class">Creating a <tt class="docutils literal"><span class="pre">WizardView</span></tt> class</a></li>
<li><a class="reference internal" href="#creating-templates-for-the-forms">Creating templates for the forms</a></li>
<li><a class="reference internal" href="#hooking-the-wizard-into-a-urlconf">Hooking the wizard into a URLconf</a></li>
<li><a class="reference internal" href="#using-a-different-template-for-each-form">Using a different template for each form</a></li>
</ul>
</li>
<li><a class="reference internal" href="#advanced-wizardview-methods">Advanced <tt class="docutils literal"><span class="pre">WizardView</span></tt> methods</a></li>
<li><a class="reference internal" href="#providing-initial-data-for-the-forms">Providing initial data for the forms</a></li>
<li><a class="reference internal" href="#handling-files">Handling files</a></li>
<li><a class="reference internal" href="#conditionally-view-skip-specific-steps">Conditionally view/skip specific steps</a></li>
<li><a class="reference internal" href="#how-to-work-with-modelform-and-modelformset">How to work with ModelForm and ModelFormSet</a></li>
<li><a class="reference internal" href="#usage-of-namedurlwizardview">Usage of <tt class="docutils literal"><span class="pre">NamedUrlWizardView</span></tt></a></li>
<li><a class="reference internal" href="#advanced-namedurlwizardview-methods">Advanced <tt class="docutils literal"><span class="pre">NamedUrlWizardView</span></tt> methods</a></li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="form-preview.html">Form preview</a></li>
    
    
      <li>Next: <a href="../gis/index.html">GeoDjango</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../../index.html">Django 1.4.5 documentation</a>
        
          <ul><li><a href="../../index.html">API Reference</a>
        
          <ul><li><a href="../index.html"><tt class="docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal"><span class="pre">contrib</span></tt> packages</a>
        
          <ul><li><a href="index.html">django.contrib.formtools</a>
        
        <ul><li>Form wizard</li></ul>
        </li></ul></li></ul></li></ul>
      </li>
  </ul>  

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../../_sources/ref/contrib/formtools/form-wizard.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Feb 21, 2013</p>
          </div> 
        
      
    </div>
    
    <div id="ft">
      <div class="nav">
    &laquo; <a href="form-preview.html" title="Form preview">previous</a> 
     |
    <a href="../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="../gis/index.html" title="GeoDjango">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>