Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango wizard: Form instantiated and clean called multiple times
    text
    copied!<p>I have a form wizard with 3 forms. The first form has only one field and uses that field to do a lookup in an external API to validate the data.</p> <p>I noticed that the requests were taking unusually long, so I just added a print statement to the form's <strong>init</strong> method and to the external API client call.</p> <p>It seems that my first form is being initialized and cleaned exactly 28 times every time I execute that step in the form wizard.</p> <p>My first form looks like this:</p> <h1>forms.py</h1> <pre><code>class MyForm1(forms.Form): issue_id = forms.CharField() def __init__(self, *args, **kwargs): print "init form 1" super(MyForm1, self).__init__(*args, **kwargs) def clean(self): cleaned_data = super(MyForm1, self).clean() print "clean issue id" issue_id = cleaned_data.get("issue_id") if issue_id is not None: try: issue = ApiCLient.get_issue(issue_id) except APIError: raise forms.ValidationError("Issue not found. Try again!") else: return cleaned_data raise forms.ValidationError("Issue not found. Try again!") </code></pre> <p>The wizard stuff is pretty standard from the Django Docs, but here it goes:</p> <h1>views.py</h1> <pre><code>class MyWizard(SessionWizardView): def done(self, form_list, **kwargs): # some logic at the end of the wizard </code></pre> <h1>urls.py</h1> <pre><code>wizard_forms = [MyForm1, MyForm2, MyForm3] ... url(r'wizard/$', login_required(views.MyWizard.as_view(wizard_forms))), </code></pre> <p>As I said before, executing the first step results in </p> <pre><code>init form 1 clean issue id </code></pre> <p>Being printed to console exactly 28 times.</p> <p>Any ideas? Is this a feature or a bug in the Django Form Wizard?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload