liveBook · Manning

Include function

As explained in Django in Action

Django's include function incorporates URL patterns from another module under a specified path prefix.

Django’s include() keeps an application’s URL patterns in its own module, then mounts them under a shared path prefix in the project routes. section 4.6.1

The request path /bands/musician/1/ first matches bands/ in the project URL file, then continues through bands.urls to the musician route and view. section 4.6.1

Mounting the bands routes

from django.urls import path, include urlpatterns = [ path("bands/", include("bands.urls")), ] The app-specific file can then define path("musician/<int:musician_id>/", views.musician, name="musician"). New bands routes stay in bands/urls.py instead of enlarging the project URL file. section 4.6.1

Listing 4.6 Registering all the URL routes in the bands app
# RiffMates/RiffMates/urls.py
...
from django.urls import path, include  #1
...
urlpatterns = [
    ...
    path('bands/', include("bands.urls")), #2
]

Inspect the complete project-level registration that imports include and mounts bands.urls beneath bands/. section 4.6.1

How Django in Action covers it

How deep it goes
Explains module inclusion, prefix registration, and request flow, but stops short of broader routing internals.
Examples
Uses the bands app, bands/urls.py, the /bands/ prefix, and a musician detail route.
What it assumes
Assumes basic Django URL patterns and views while showing how app-specific routing files connect to the project.
What you can do after
Build it from scratch by registering an app’s URL module under a project-level path prefix.
How it connects
Connects URL patterns, Django apps, path(), views, modules, and URL routing.

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.