Performance: Redirects with redirect function
This affects page load speed by adding extra HTTP requests and delays before the final content loads.
def submit_view(request): if request.method == 'POST': # process form return redirect('/final-url/') # direct redirect to final destination
def submit_view(request): if request.method == 'POST': # process form return redirect('/old-url/') # redirects to another URL which then redirects again # /old-url/ view redirects again to /final-url/
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple chained redirects | 0 (no DOM until final page) | 0 | 0 | [X] Bad |
| Single direct redirect | 0 (no DOM until final page) | 0 | 0 | [OK] Good |
redirect function do in a view?redirect to send a user to a URL path '/home/'?return redirect('/home/') correctly calls redirect and returns the response.from django.shortcuts import redirect
def my_view(request):
return redirect('home')from django.shortcuts import redirect
def go_home(request):
redirect('/home/')post in Django. Which is the correct way to use redirect?Pass the test and this pattern moves unknown