0👍
It means user can posted many times by click F5
or (Back-Sumbit)(Back-Sumbit)(Back-Sumbit)
If it is not return redirect?
I think it can help prevent irrigation.
0👍
In the example, votes can be inserted into the database via <int:question_id>/vote/
.
If the user submits POST data via a form to this url, and we return this same page as an HttpResponse
, the POST contents will be remembered from the request and will be resubmitted. If they refresh this same page they were on, the contents of the POST will be also resubmitted. If they visit the vote page as a bookmark, and the browser remembers their POST data, another submission will be created. If the user presses the back button to get back to the vote page from somewhere else, and we return an HttpResponse
, the POST data will be remembered, and another submission will occur. These will result in duplicate database entries.
If instead we use HttpResponseRedirect
to send the user a view (like a results page for that question), the POST contents will not be transmitted to the new page.
An interesting aside for your example: If you were to respond with the same vote page after submission via HttpResponseRedirect
, the user would get a paragraph error message, as the details view & vote view serve different purposes (details shows the form, while vote handles POST data or lack thereof). However our POST data from our request will not carry over given we have used the correct method for this problem.
- [Django]-How to correctly load data from a table to a form?
- [Django]-ModuleNotFoundError: No module named 'debug_toolbar' Django 3.1