[Answer]-Residual values in template formset fields with modelformset

1👍

You are generating the form with POST data (to save it).
Then rendering the same formset with the same POST data. This is useful for displaying errors, but in case of success, not what you want

The standard pattern is to save the form / formset, (then assuming no errors) redirect. in Your case redirect to a GET version of the form.

before the first “else” add something like

        return HttpResponseRedirect("add the url to your view here")      

It will then run the same code, but without the POST data. Alternatively, add a different url to a success page.

Here is the example in the docs (for a single form, but its the same principle):
https://docs.djangoproject.com/en/1.8/topics/forms/#the-view

You are missing the line:

        return HttpResponseRedirect('/thanks/')

Leave a comment