Python 嵌套Django表单:';ManagementForm数据丢失或已被篡改';
所以我环顾四周,似乎没有人遇到过与我造成这个看似常见的错误相同的问题。我在html中呈现一些表单,如下所示:Python 嵌套Django表单:';ManagementForm数据丢失或已被篡改';,python,html,django,forms,nested-forms,Python,Html,Django,Forms,Nested Forms,所以我环顾四周,似乎没有人遇到过与我造成这个看似常见的错误相同的问题。我在html中呈现一些表单,如下所示: <form method="post" action=""> {{ tags_formset.management_form }} <!-- code displaying this formset --> ... <!-- --> <form method="post" action=""> {{ add_al
<form method="post" action="">
{{ tags_formset.management_form }}
<!-- code displaying this formset -->
...
<!-- -->
<form method="post" action="">
{{ add_all_form.management_form }}
{{ add_all_form.addTagsToAll }}
<input type="submit" value="Add To Displayed Applicants" />
</form>
<form method="post" action="">
{{ remove_all_form.management_form }}
{{ remove_all_form.removeTagsFromAll }}
<input type="submit" value="Remove From Displayed Applicants" />
</form>
<input type="submit" value="Save Changes" />
</form>
我真的搞不清楚出了什么问题。我不知道为什么add_all_表单有效,而remove_all_表单无效,因为我基本上复制并粘贴了所有相关内容(如果需要,我可以发布Forms.py文件中的代码,但我认为问题不在那里…)
请帮忙 您应该只使用一个
标记。在这里,您可以有任意多个submit按钮,也可以显示任意多个表单,但所有表单都应该位于一个
标记内
然后,所有的管理数据将以表单提交的形式正确发送,您的问题应该得到解决
<form method="post" action="">
{{ tags_formset.management_form }}
<!-- code displaying this formset -->
...
<!-- -->
{{ add_all_form.management_form }}
{{ add_all_form.addTagsToAll }}
<input type="submit" value="Add To Displayed Applicants" />
>
{{ remove_all_form.management_form }}
{{ remove_all_form.removeTagsFromAll }}
<input type="submit" value="Remove From Displayed Applicants" />
<input type="submit" value="Save Changes" />
{{tags_formset.management_form}
...
{{add_all_form.management_form}
{{add_all_form.addTagsToAll}
>
{{remove_all_form.management_form}
{{remove_all_form.removeTagsFromAll}
您的视图可以保持原样。谢谢您的回答!它工作得很好。我从来没有想过我不应该为每个表单添加表单标签。这看起来就像是你会做的事,所以我甚至没有质疑。再次感谢!
<form method="post" action="">
{{ tags_formset.management_form }}
<!-- code displaying this formset -->
...
<!-- -->
{{ add_all_form.management_form }}
{{ add_all_form.addTagsToAll }}
<input type="submit" value="Add To Displayed Applicants" />
>
{{ remove_all_form.management_form }}
{{ remove_all_form.removeTagsFromAll }}
<input type="submit" value="Remove From Displayed Applicants" />
<input type="submit" value="Save Changes" />