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