liveBook · Manning

Urlpatterns

As explained in Django in Action

urlpatterns is the Django URL-configuration variable containing a list of path objects.

urlpatterns is the Django URL-configuration variable: a Python list of path objects that connects incoming URLs with the code handling them. Each path object maps a URL to a view or loads another mapping file, allowing URL definitions to form a hierarchy. section 1.1.1 section 2.6

A Django request follows this route:

Registering a RiffMates route

The central RiffMates/RiffMates/urls.py file can retain the Django Admin route and add the home app's credits view: path("admin/", admin.site.urls) and path('credits/', home_views.credits). Importing the module as home_views keeps similarly named views.py modules distinguishable. URL patterns omit the leading slash because Django supplies it. section 2.6

Listing 2.3 Register your view
# RiffMates/RiffMates/urls.py
from django.contrib import admin

from django.urls import path

from home import views as home_views  #1

urlpatterns = [
    path("admin/", admin.site.urls),
    path('credits/', home_views.credits),  #2
]

Use the complete route-registration listing to see the imports, urlpatterns list, existing Admin mapping, and credits view mapping together. section 2.6

How Django in Action covers it

How deep it goes
Defines the list and path-object arguments, then traces matching to view invocation, but does not detail advanced pattern syntax.
Examples
Demonstrates the Django Admin route and a RiffMates credits route using an aliased home.views module.
What it assumes
Assumes basic Python imports and functions while explaining Django routing, views, requests, and WSGI context.
What you can do after
Operate/configure Django URL routing by registering a view and understanding how requests reach it.
How it connects
Connects URL patterns with urls.py, path objects, Django views, WSGI, the Django Admin, and MVC terminology.

Related concepts

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.