34. URL Router

34.1. Global URLs

34.2. In app URLs

34.3. urlpatterns

Code 34.1. Path usage
from django.conf import settings
from django.contrib import admin
from django.urls import path
from django.urls import include
import debug_toolbar

urlpatterns = [
    path('admin/', admin.site.urls),
    path('contact/', include(('contact.urls', 'contact'), namespace='contact')),
]

if settings.DEBUG:
    urlpatterns += [
        path('__debug__/', include(debug_toolbar.urls)),
    ]

34.4. path

Code 34.2. Path usage
from django.urls import path
from contact.views import ListView, DetailView, ContactAPI


urlpatterns = [
    path('<int:id>/', DetailView.as_view(), name='details'),
    path('', ListView.as_view(), name='list'),
    path('api/', ContactAPI.as_view())
]

34.5. url

Code 34.3. Path usage

34.6. include

Code 34.4. Path usage

34.7. URLs reversing

34.8. URLs in templates