FormWizardのtemplateの設置場所を変更
前回説明し忘れたのですが、デフォルトでのFormWizardのテンプレート名は'wizard.html'
設置場所は、TEMPLATE_DIRS/forms/wizard.html
これはソースを見るとわかります。
\django\contrib\formtools\wizard.py
def get_template(self, step): """ Hook for specifying the name of the template to use for a given step. Note that this can return a tuple of template names if you'd like to use the template system's select_template() hook. """ return 'forms/wizard.html'
となっています。
これを、作成したforms.pyに少し手を加えてオーバーライドすると"appname/wizard.html"などに変更することが出来ます。
from django import newforms as forms from django.http import HttpResponseRedirect from django.contrib.formtools.wizard import FormWizard class ContactOne(forms.Form): name = forms.CharField() email = forms.EmailField() class ContactTwo(forms.Form): CHOICES = [(x, x) for x in ("I like your site", "I hate your site", "I don't care")] feeling = forms.ChoiceField(choices = CHOICES) message = forms.CharField(widget = forms.widgets.Textarea) class ContactWizard(FormWizard): def get_template(self, step): return 'appname/wizard.html' def done(self, request, form_list): return HttpResponseRedirect('/contact/thanks/')
これを利用すれば、ステップごとに別のテンプレートを使うようにすることが出来るかな?