4.8. URL Router

4.8.1. Global URLs

4.8.2. In app URLs

4.8.3. urlpatterns

Listing 501. 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)),
    ]

4.8.4. path

Listing 502. 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())
]

4.8.5. url

Listing 503. Path usage

4.8.6. include

Listing 504. Path usage

4.8.7. URLs reversing

4.8.8. URLs in templates