表单集验证时出现 ManagementForm 数据丢失错误
在views.py中创建表单集:
ffact = formset_factory(Form,extra=somenum]))
fset = ffact(prefix='pfix')
在views.py中进行验证:
ffact = formset_factory(Form,extra=3))
fset = ffact(request.POST)
if fset_is.valid():
blah blah
这会导致异常类型:/app/index/处的ValidationError 异常值:[u'ManagementForm 数据丢失或已被篡改'] django-docs 确实提到过这一点。我不确定如何提供管理数据。我尝试了类似 this 的方法,
try:
fset = ffact(request.POST)
except ValidationError:
fset = None
if fset and fset.is_valid():
blah blah
但我仍然遇到同样的错误。任何想法?谢谢。
formset creation in views.py:
ffact = formset_factory(Form,extra=somenum]))
fset = ffact(prefix='pfix')
validation in views.py:
ffact = formset_factory(Form,extra=3))
fset = ffact(request.POST)
if fset_is.valid():
blah blah
this is resulting in Exception Type: ValidationError at /app/index/
Exception Value: [u'ManagementForm data is missing or has been tampered with'] django-docs
did mention about this. I'm not sure how to provide management data. I tried something like this ,
try:
fset = ffact(request.POST)
except ValidationError:
fset = None
if fset and fset.is_valid():
blah blah
But still i get the same error.Any ideas? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
管理数据在
request.POST
中吗?http://docs.djangoproject.com/en/ dev/topics/forms/formsets/#understanding-the-managementform
以下信息必须位于
request.POST
中:有一个渲染隐藏字段的快捷方式:
{ { my_formset.management_form }}
Is the management data in
request.POST
?http://docs.djangoproject.com/en/dev/topics/forms/formsets/#understanding-the-managementform
The following info has to be in
request.POST
:There is a shortcut for rendering the hidden fields:
{{ my_formset.management_form }}
在模板中呈现 formset.management_form
这允许管理表单数据可用,因此数据是完整的。但是,如果在生成表单集时添加前缀,
添加前缀应该可以解决该问题。
rendering the formset.management_form in the template
this allows the management form data available and hence data is complete.But if prefix is added while genarating formsets
adding prefix should fix that issue.