6.6 Revisiting Homepage Redirection

In Chapter 5: Creating Webpages with Controllers in Django, we saw how to use the HttpResponseRedirect class and redirect shortcut to redirect a URL pattern to another URL path and pattern (respectively) via a function view. At the time, we did not understand how Django was reversing the URL pattern into a URL. The redirect shortcut should now be much clearer. For the sake of clarity, let’s walk through the process again.

We started with the code shown in Example 6.46 in /suorganizer/views.py.

Example 6.46: Project Code

suorganizer/views.py in 2e8036623d

1  from django.http import HttpResponseRedirect 2 3 4  def redirect_root(request): 5      return HttpResponseRedirect('/blog/' ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.