I'm looking to redirect a list of old URLs to a list of new URLs in a Django/Heroku app.
Since I'm using Heroku, I can't just use an .htaccess
file.
I see that rails has rack-rewrite, but I haven't seen anything like that for Django.
Django has redirects app, which allows to store redirects list in database: https://docs.djangoproject.com/en/dev/ref/contrib/redirects/
Also here a generic RedirectView:
https://docs.djangoproject.com/en/1.3/ref/class-based-views/#redirectview
And the lowest level is HttpResponseRedirect:
https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponseRedirect
You can use redirect. Please check below code.
from django.shortcuts import redirect
return redirect(
'/', permanent=True
)
It worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With