19.5.3 Using Django’s Views to Make Login and Logout Pages

If we pop open Django’s source code, we can browse to django/contrib/auth/views.py and look at the definition of login(), shown in Example 19.30.

Example 19.30: Python Code

# django/contrib/auth/views.py def login(request, template_name='registration/login.html',            redirect_field_name=REDIRECT_FIELD_NAME,            authentication_form=AuthenticationForm,            current_app=None, extra_context=None):

The parameter we’re interested in overriding is template_name.

To start, we should import all of the tools we will need for our URL patterns, as shown in Example 19.31.

Example 19.31: Project Code

user/urls.py in 07122a7dd9

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.