0 day streak
python / beginner
Snippet

Preventing Form Re-submission

After a successful POST request, you should always return a redirect. This prevents the browser from prompting the user to resubmit the data if they refresh the page.

snippet.py
python
1
2
3
4
5
6
from django.shortcuts import redirect
def my_view(request):
if request.method == 'POST':
# Process form data here
return redirect('success_url')
django
Breakdown
1
from django.shortcuts import redirect
Imports the helper function to redirect users to a different URL.
2
return redirect('success_url')
Sends the user to the success page after the POST data is processed.