我有一个简单的formset:
TextAdFormset = formset_factory(TextAdForm, formset=BaseFormSet, max_num=3)
if request.method == "POST":
form = CampaignForm(request.POST)
text_ad_formset = TextAdFormset(request.POST)
if form.is_valid() and text_ad_formset.is_valid():
....
else:
form = CampaignForm()
text_ad_formset = TextAdFormset()
在模板中自定义呈现:
<form action="" method="POST">{% csrf_token %}
{{ text_ad_formset.management_form }}
{% for text_ad_form in text_ad_formset.forms %}
{{ text_ad_form.headline1 }}
{% endfor %}
</form>
我得到错误:
ValidationError at /
[u'ManagementForm data is missing or has been tampered with']
调试:
Django版本1.11
我有什么想法可以调试这个问题吗?
更新
我已经检查了在formset中提交的POST数据。当只提交一个表单时,它可以正常工作:
u'form-TOTAL_FORMS': [u'1']
但是当我提交带有两个表单的formset时,它会出现一个列表:
u'form-TOTAL_FORMS': [u'2', u'']
在POST数据的浏览器的调试屏幕中显示为:
form-TOTAL_FORMS u''
这可能与错误有关吗?