include() (Django URLs)
include() lets a Django URLconf delegate a set of URLs to another app's urls.py. The project's root urls.py uses it to attach each app's routes under a path prefix, keeping URL configuration modular.
Django
Rather than listing every URL in one giant file, include() pulls in another module's urlpatterns. path('blog/', include('blog.urls')) means every pattern in blog/urls.py is served under /blog/, so the app owns its own URL space.
This keeps apps self-contained and reusable: the app defines URLs relative to itself, and the project decides where to mount them. You can change the prefix in one place without touching the app.
include() pairs naturally with namespacing — set app_name in the app's urls.py and the included patterns become reachable as 'blog:detail', preventing name clashes between apps that use the same view names.
Syntax
path("blog/", include("blog.urls"))Examples
Python
# mysite/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("blog/", include("blog.urls")),
path("api/", include("api.urls")),
]