我正在尝试使用普通迭代(就像 Django 文档中显示的那样)为表单集中的每个表单获取 clean_data:
MyFormSet = formset_factory(form=MyForm, formset=MyBaseFormSet)
my_form_set = MyFormSet(request.POST or None, initial = my_data, prefix = 'myform')
之后,我正在验证并尝试遍历每个表单并打印它的值,如下所示:
for f in my_form_set.forms:
print(f.cleaned_data)
但我得到的结果是这样的:
<QueryDict: {"myform-0-field_a" : "this is a", "myform-1-field_a" : "this is second a"}>
<QueryDict: {"myform-0-field_a" : "this is a", "myform-1-field_a" : "this is second a"}>
我期望获得一对单独的键和值,但相反,对于每次迭代,我都会获得整个 POST 数据。
我期待这样的事情:
迭代 0:
"field_a" : "this is a"
迭代 1:
"field_a" : "this is second a"
我想念哪里?
谢谢