Skip to content
Advertisement

Django execute previous action on refresh

I have tried to add a book in to the database using an HTML form. After the submission, the page redirect to a page where all the books are listed .Then whenever I refresh the page , the data is became duplicated. How do I resolve this problem?

urls.py

JavaScript

views.py

JavaScript

Template file:

JavaScript

Advertisement

Answer

This is most common problem, the thing is that after dealing with POST data you should always return an HttpResponseRedirect, the tip is not specific to Django, but it’s a good web practice in general so:

urls.py:

JavaScript

views.py:

JavaScript

success.html

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement