5.10.2 Redirecting the Homepage with Views

Rather than simply displaying a webpage on our homepage, we will instead redirect the user to the desired URL. In this instance, http://site.django-unleashed.com/ will redirect to http://site.django-unleashed.com/blog/, which is the post_list() view.

To redirect a URL, we need a view. This creates a minor problem: we are redirecting our site-wide homepage with a view, which at this point exists only in app directories. However, this code does not belong in either our organizer or blog apps. Although Django does not anticipate the need for site-wide views.py, nothing is stopping us from creating /suorganizer/views.py. Inside, we write the code shown in Example 5.75.

Example 5.75: Project Code

suorganizer/views.py ...

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.