我使用kwargs
最初填充我djnago形式,Django的表單提交錯誤
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'是請求,那麼這段代碼會給你發佈的數據。請張貼實際的視圖,加上你得到的錯誤。 –
請現在看看,希望它很清楚。 – rhn89