我在从表单集中访问表单数据时遇到问题。我附上了代码:
####FORM
class ActionTypeForm(forms.Form):
action_name = models.CharField(max_length=20)
description = models.CharField(max_length=250, blank=True, null=True)
####VIEW
dataset = request.POST
ActionTypeFormSet = formset_factory(ActionTypeForm)
formset = ActionTypeFormSet(dataset)
if formset.is_valid():
for form in formset.cleaned_data: #I ALSO TESETED formset.forms
customer.create_actiontype(form['action_name'], form['description'])
错误是我无法获取表单 ['action_name']。formset.is_valid() 返回 True
错误
异常类型:KeyError
异常值:'action_name'
发布数据
form-0-action_name u'a'
form-2-description u'sadsa'
form-0-description u'a'
表格-MAX_NUM_FORMS u''
form-1-description u'asd'
表格-TOTAL_FORMS u'3'
form-1-action_name u'as'
form-INITIAL_FORMS u'0'
csrfmiddlewaretoken u'c4fa9ddb4ec69ac639d7801eb14979f2'
form-2-action_name u'asda'