【发布时间】:2013-12-26 10:52:30
【问题描述】:
我最初使用kwargs 填充我的 djnago 表单,
-
Forms.py
class myForm(Forms.Form): textbox1 = forms.CharField() dropdown1 = forms.ChoiceField() def __init__(self,*args,**kwargs): choices = kwargs.pop('choices') super(myForm,self).__init__(*args,**kwargs) self.fields['dropdown1'] = forms.ChoiceField(choices=choices) -
views.py
def myjob(req): ch = {("1","A"),("2","B")} if req.method == "POST": frm = myForm(data=req.POST) # throws error saying can't find choices in Forms.py else: frm = myForm(choices=ch) # no problem here
此代码在尝试再次调用 init 时在提交数据时引发错误。
如何正确提交?
【问题讨论】:
-
这个问题不清楚。假设
req是请求,该代码确实为您提供了已发布的数据。请发布实际视图,以及您得到的错误。 -
请看一下,希望清楚。