At any point, your urlpatterns
can include other URLconf modules. This essentially roots a set of URLs below other ones. For example, here's an excerpt of the URLconf for the Django website itself. It includes a number of other URLconfs:
from django.conf.urls import include, url urlpatterns = [ # ... url(r'^community/', include('django_website.aggregator.urls')), url(r'^contact/', include('django_website.contact.urls')), # ... ]
Note that the regular expressions in this example don't have a $
(end-of-string match character) but do include a trailing slash. Whenever Django encounters include()
, it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing. Another possibility is to include additional URL patterns by using a list of url()
instances. For example, consider this URLconf:
from django.conf.urls import include, url...