I have a form and a formset on my template. The problem is that the formset is throwing validation error claiming that the management form is \"missing or has been tampered
To avoid this error just wrap your formset POST bounding in a try/except block like so.
from django.core.exceptions import ValidationError # add this to your imports
if request.method == 'POST':
try:
delblogformset = delblog(request.POST)
except ValidationError:
delblogformset = None
if delblogformset and delblogformset.is_valid():
delblogformset.save()
return HttpResponseRedirect('/home')
The POST request from your blogform
lacks the 'ManagementForm' hidden input that is required for your delblogformset
and hence the validation error is thrown. We wrap in a try/except block because we know that if ValidationError
has been raised than the POST was meant for your blogform
and not delblogformset
.
For more information see django docs: http://docs.djangoproject.com/en/dev/topics/forms/formsets/#understanding-the-managementform