我是 django 的新手,正在尝试使用表单向导。我正在关注官方文档,并从中尝试以下示例:
from django import forms
from django.contrib.formtools.wizard.views import SessionWizardView
class ContactForm1(forms.Form):
subject = forms.CharField(max_length=100)
sender = forms.EmailField()
class ContactForm2(forms.Form):
message = forms.CharField(widget=forms.Textarea)
class ContactWizard(SessionWizardView):
pass # I tried with a done() method as well, just to be sure.
initial = {
'0': {'subject': 'Hello', 'sender': 'user@example.com'},
'1': {'message': 'Hi there!'}
}
wiz = ContactWizard.as_view([ContactForm1, ContactForm2], initial_dict=initial)
form1 = wiz.get_form('0')
form2 = wiz.get_form('1')
但是上面在该行引发了以下错误form1 = wiz.get_form('0')
:
Traceback (most recent call last):
File "fw.py", line 19, in <module>
form1 = wiz.get_form('0')
AttributeError: 'function' object has no attribute 'get_form'
这是文档中的错误,django 本身,还是(很可能)我的代码有问题?我在 Linux (Ubuntu) 上使用 django 1.4.1。
谷歌搜索只显示两个相关链接:一个来自 django IRC,一个来自Django Brasil,但没有一个链接有任何解决方案。