#30404: Docs: "Using a model formset in a view" example does not handle the case
where validation fails on POST
-------------------------------------------+------------------------
Reporter: Stephen G Tuggy | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
The URL is here:
[https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a
-model-formset-in-a-view] The 2.2 and 1.8 documentation versions suffer
from the same problem (and probably every other version in between).
You will notice that the Method-Based View `manage_authors` handles the
case where `request.method == 'POST'` and `formset.is_valid()`, but
**not** the case where `request.method == 'POST'` and `formset` is not
valid. As a result, newbies (like myself) following this example may not
implement this case either. Then, if the data POSTed to this view passes
client-side validation but not server-side validation, the user will get
an error message:
`The view '...' didn't return an HttpResponse object. It returned None
instead`
See this StackOverflow post, for example:
[https://stackoverflow.com/questions/50202477/the-view-blog-views-post-
list-didnt-return-an-httpresponse-object-it-returned?rq=1] And this post:
[https://www.freecodecamp.org/forum/t/didnt-return-an-httpresponse-object-
it-returned-none-instead/216155/2]
As far as I have been able to determine, the correct code behavior in this
situation is pretty much the same as what you do for a GET: Construct a
context dictionary, starting with RequestContext, then return the result
of rendering the formset once more. One caveat: Make sure your template
has a spot to display non-field errors.
Is this correct? Thank you for your attention.
--
Ticket URL: <https://code.djangoproject.com/ticket/30404>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/056.cc14bddbc07130641281aab11b7509dc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.