📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Django Framework Django URLs

Django URLs

5 min read Quiz at the end
Configure URL patterns with path(), include(), app_name namespaces, and type converters.

URL Configuration

# mysite/urls.py
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path("admin/", admin.site.urls),
    path("",       include("blog.urls")),
    path("api/",   include("api.urls")),
    path("auth/",  include("django.contrib.auth.urls")),
]

# blog/urls.py
from django.urls import path
from . import views

app_name = "blog"

urlpatterns = [
    path("",                         views.PostListView.as_view(), name="post-list"),
    path("posts/<slug:slug>/",       views.PostDetailView.as_view(), name="post-detail"),
    path("posts/create/",            views.PostCreateView.as_view(), name="post-create"),
    path("posts/<slug:slug>/edit/",  views.PostUpdateView.as_view(), name="post-update"),
    path("posts/<slug:slug>/delete/",views.PostDeleteView.as_view(), name="post-delete"),
]

# In templates
{% url "blog:post-list" %}
{% url "blog:post-detail" slug=post.slug %}
Topic Quiz · 2 questions

Test your understanding before moving on

1. What does app_name = "blog" in urls.py enable?
💡 app_name creates a namespace so routes can be referenced as "blog:post-list".
2. How do you generate a URL in a Django template?
💡 {% url "name" args %} is the Django template tag for generating URLs.