[Django]-ManagementForm data is missing or has been tampered with

45👍

You have to render the management form in your template. The docs explain why and how; some selected quotes:

This form is used by the formset to manage the collection of forms contained in the formset. If you don’t provide this management data, an exception will be raised[.]

The management form is available as an attribute of the formset itself. When rendering a formset in a template, you can include all the management data by rendering {{ my_formset.management_form }} (substituting the name of your formset as appropriate).

12👍

write {{ formset.management_form }} above your {% for form in formset %}

like this

{{ formset.management_form }}
{% for form in formset %}
👤yahya

4👍

I had the same problem trying to use two formset on same page, I’m adding it’s solution coz I didn’t find it anywhere else.

Make sure you add the prefix param as

formset = ProgressFormSet(request.POST or None, prefix="fs1")

to GET and POST request both.

👤AviKKi

0👍

For those that do have the {{ formset.management_form }} in their template, and do use the correct variable name for the formset, but are still seeing the error message

ManagementForm data is missing or has been tampered with

Make sure not to initialize your formset with empty data

For example, data=None is no problem:

>>> MyFormSet(data=None).non_form_errors()
[]

However, data={} is a problem:

>>> MyFormSet(data={}).non_form_errors()
['ManagementForm data is missing or has been tampered with. Missing fields: ...']

Beware

The latter case also arises if you try to do MyFormSet(data=request.POST) when handling a GET request, because request.POST will then be an empty QueryDict.

If required, a workaround would be e.g. MyFormSet(data=request.POST or None).

👤djvg

Leave a comment