1👍
✅
You will want to handle successful form submissions with the Post/Redirect/Get pattern to prevent the back button from returning to the previous post. In your Django project this is done by returning a redirect
from the view instead of an HttpResponse
. Redirect docs
from django.shortcuts import redirect
def view_function(request, ...):
... # code processing the POST
if post_request_successful:
return redirect(path)
else:
return HttpResponse(...) # or render(...) or whatever you usually return
Where path
is a url. Most likely you want to either use the same path in the request request.path
or get a path by reversing a url name from your urls.py file (from django.shortcuts import reverse
). Reverse docs
Source:stackexchange.com