フォームにはいくつかのフォームがありますが、フォームの状態は最終ステップでのみ維持され、done()は実行されません。最終フォームにのみ保存されたSessionWizardView状態done()は実行されません
私は次のものを作成しました.Djangoのドキュメントの例に大きく基づいています。最後のステップは、ステップ間を移動するときに状態を保存する唯一のステップだと思われます。テンプレートの
class OneForm(Form):
field_one = forms.CharField(label='1', max_length=100)
field_two = forms.CharField(label='2', max_length=100)
field_three = forms.CharField(label='3', max_length=100)
class TwoForm(Form):
field_one = forms.CharField(label='4', max_length=100)
field_two = forms.CharField(label='5', max_length=100)
field_three = forms.CharField(label='6', max_length=100)
TEST_WIZARD_FORMS = [
("one", OneForm),
("two", TwoForm),
]
TEST_TEMPLATES = {
'one': 'tour/one.html',
'two': 'tour/two.html',
}
class TestWizardView(SessionWizardView):
form_list = TEST_WIZARD_FORMS
def done(self, form_list, **kwargs):
print('done executed')
return reverse('home')
def get_template_names(self):
return [TEST_TEMPLATES[self.steps.current]]
このI、ステップ1にデータを入力した場合は、ステップ2と、データを入力し、ステップに戻る進む
<html>
<body>
<p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
<form action="" method="post">{% csrf_token %}
<table>
{{ wizard.management_form }}
{% if wizard.form.forms %}
{{ wizard.form.management_form }}
{{ wizard.form.non_field_errors }}
{{ wizard.form.errors }}
{% for form in wizard.form.forms %}
{{ form }}
{% endfor %}
{% else %}
{{ wizard.form }}
{% 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 %}
<button name="wizard_goto_step" type="submit" value="{{ wizard.steps.next }}">"next step"</button>
<input type="submit" value="submit"/>
</form>
</body>
</html>
(one.htmlとtwo.html両方が同一です) 1の場合、最初のステップではデータは保存されず、フォームエラーは表示されません。次のステップに戻ってステップ2に戻ると、ステップ2のデータはまだ残っています。意図的にステップ1に無効なデータを置くと、ウィザードはエラーを表示せずにステップ2に進みますので、フォームの検証も行われません。
フォームを送信すると、done()は実行されません。これは、最後のステップだけが実際に成功した場合には理にかなっていますが、ステップ1でエラーが発生していないと私は困惑しています。
最終フォーム以外のフォームデータは維持されないのはなぜですか?フォームデータを実際に検証する唯一のステップはなぜですか?なぜ実行されないのですか?
更新:フォームの検証がやっぱ起こっている表示され、私はまだ実行され得るように見えることはありません)、それはポスト機能の関連情報を印刷を通じて続くが、(行って見ます。
ありがとうございます。