0
我读http://docs.djangoproject.com/en/dev/ref/forms/fields/views.py Django中的Field.initial?
>>> class CommentForm(forms.Form):
... name = forms.CharField(initial='Your name')
... url = forms.URLField(initial='http://')
... comment = forms.CharField()
>>> f = CommentForm(auto_id=False)
>>> print f
<tr><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr>
<tr><th>Url:</th><td><input type="text" name="url" value="http://" /></td></tr>
<tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
在我来说,我想在views.py 初始场,因为我的初步数据(myinit_data)我得到它在views.py
我forms.py
#...
class SendMailForm(forms.Form):
to = forms.EmailField(initial=myinit_data, widget = forms.TextInput(attrs={'size': '50'}))
subject = forms.CharField(widget = forms.TextInput(attrs={'size': '50'}))
body = forms.CharField(widget = forms.Textarea(attrs={'cols': '50', 'rows': '10'}), required=False)
我views.py
#....
myinit_data = list_of_data_generated # for example [[email protected],[email protected],[email protected]]
form_sendmail = SendMailForm()
我怎么能从views.py初始化我的领域
谢谢! :)
感谢您的帮助 – kn3l 2009-12-23 12:14:25
“但myinit_data必须是一个字典,其中键为字段名称。” 我不知道具体如何在表单中的特定领域初始化。例如,形式为.EmailField的 。 – kn3l 2009-12-24 02:21:01
'{'myfieldname':'myvalue'}' - 听起来您需要对Python进行基本的介绍,请尝试http://wiki.python.org/moin/BeginnersGuide/NonProgrammers上列出的一些教程 – 2009-12-24 09:53:10