Invalid ManagementForm data error during form validation

creating forms in views.py:

ffact = formset_factory(Form,extra=somenum]))
fset = ffact(prefix='pfix')

check in views.py:

ffact = formset_factory(Form,extra=3))
fset = ffact(request.POST) 
if fset_is.valid():
    blah blah

this leads to an exception type: ValidationError at / app / index / Exception value: [u'ManagementForm data is missing or was tampered with] django-docs mentioned this. I am 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? Thank.

+3
source share
2 answers

displaying the form formet.management_form in the template

{{fset.management_form}}

this allows you to obtain data management forms and, therefore, the data is completed. But if prefix is ​​added when propagating forms

.

fset = ffact(request.POST,prefix='pfix')
+8

request.POST? http://docs.djangoproject.com/en/dev/topics/forms/formsets/#understanding-the-managementform

request.POST:

data = {
    'form-TOTAL_FORMS': u'1',
    'form-INITIAL_FORMS': u'0',
    'form-MAX_NUM_FORMS': u'',
}

: {{ my_formset.management_form }}

+7

Source: https://habr.com/ru/post/1796087/


All Articles