正在触发管理表单集错误

Management Formset error is getting triggered

下面的 HTML 代码返回 ['ManagementForm data is missing or has been tampered with']。这个 HTML 给了我想要的自定义外观,但为什么会这样?我不明白,因为我已经声明了 management_data 标签。

HTML

<form method="POST" enctype="multipart/form-data" action=".">
{{ formset.management_data }}

<!-- Security token -->
{% csrf_token %}

{{ formset.non_form_errors.as_ul }}
<table>
    {% for form in formset.forms %}
        {% if forloop.first %}
        <thead>
            <tr>
                 {% for field in form.visible_fields %}
                     <th name={{field.label}}>{{ field.label }}</th>
                 {% endfor %}
            </tr>
            </thead>
            {% endif %}
            <tr class="{% cycle row1 row2 %}">
                {% for field in form.visible_fields %}
                    <td name={{field.label}}>
                        {# Include the hidden fields in the form #}
                        {% if forloop.first %}
                        {% for hidden in form.hidden_fields %}
                        {{ hidden }}
                        {% endfor %}
                        {% endif %}
                        {{ field.errors.as_ul }}
                        {{ field }}
                    </td>
                {% endfor %}
            </tr>
    {% endfor %}
</table>
</form>

您需要在模板中包含 {{ formset.management_form }} 而不是 {{ formset.management_data }}Docs

<form method="POST" enctype="multipart/form-data" action=".">
    {{ formset.management_form }}
    {% csrf_token %}
    ...