This wraps up this guide on HTTP redirects with Django. Congratulations: you have now touched on every aspect of redirects all the way from the low-level details of the HTTP protocol to the high-level way of dealing with them in Django.
You learned how an HTTP redirect looks under the hood, what the different status codes are, and how permanent and temporary redirects differ. This knowledge is not specific to Django and is valuable for web development in any language.
You can now perform a redirect with Django, either by using the redirect response classes HttpResponseRedirect
and HttpResponsePermanentRedirect
, or with the convenience function django.shortcuts.redirect()
. You saw solutions for a couple of advanced use cases and know how to steer clear of common pitfalls.
Here are resources for more information on Django redirects and HTTP redirects:
- HttpResponseRedirect: Django documentation
redirect() shortcut
: Django documentationRedirectView
class: Django documentation- HTTP RFC, 3xx section
- Common Weakness Enumeration article URL Redirection to Untrusted Site
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.