liveBook · Manning

Django.contrib.auth.urls

As explained in Django in Action

django.contrib.auth.urls is a Django URL module containing URL mappings for built-in authentication and user-management views.

django.contrib.auth.urls is a ready-made URL module for Django’s authentication and user-management views. Include it in the project URLconf instead of wiring each built-in view manually. section 6.3

Think of it as a bundle of routes: Django supplies the view logic, while your project supplies the matching templates and site-specific appearance. The login route expects registration/login.html. section 6.3

Mount the authentication routes

Add this entry to urlpatterns, commonly beside the admin route: path('accounts/', include('django.contrib.auth.urls')). The login view then becomes available at /accounts/login/. Create templates/registration/login.html with a POST form containing {% csrf_token %}, {{form.as_p}}, and a submit button.

When a protected view redirects an unauthenticated visitor to login, Django adds a next query parameter so successful authentication can return the visitor to the original URL. section 6.3

How Django in Action covers it

How deep it goes
Explains inclusion, login routing, template requirements, and redirects, but defers custom forms and CSRF details.
Examples
Uses an accounts/ URL prefix, /accounts/login/, registration/login.html, and a username-and-password form.
What it assumes
Assumes basic Django URLconf and template knowledge while deferring custom form construction and detailed CSRF explanation.
What you can do after
Operate/configure built-in authentication routes and provide the login template they require.
How it connects
Connects URLconf inclusion with authentication, user management, login_required, templates, forms, and CSRF protection.

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.