Django URL Routing
URL patterns connect paths to views. A named route gives templates and Python code a stable way to build a link when the path spelling changes.
How it works
The workshops app declares an application namespace and uses slug and integer path converters. reverse turns a route name and arguments into a path; resolve identifies the matching view information for a path. Keep business lookups in the view rather than trying to encode every validation rule in the URL. Route names should describe the destination’s role and stay unique within their namespace.
Run in the supplied local Django project
This lesson uses Django 5.2.18 LTS with Python 3.12. Download the source downloader and run node download-project.mjs http://127.0.0.1:8000 with Node 22 while previewing locally. It creates a new bhylu-django-lab folder and refuses to overwrite an existing one. After deployment, the default base is bhylu.com; until then use your local preview URL.
Inside that new folder, create a virtual environment, install requirements.txt and run the complete lesson file shown below. Every lesson creates a fresh in-memory SQLite database and temporary upload storage. It does not edit the interactive lab’s db.sqlite3 or Bhylu’s database. The visible listing below is the lesson’s core code; its complete downloaded file includes the shared bootstrap.
Django does not run in Bhylu’s current browser playground. No Apache, MySQL or global PHP configuration change is needed. See the setup lesson for the full project and commands.
Example
Run .venv\Scripts\python.exe lessons\routes.py from the downloaded project root. Download the complete lesson file; keep it under lessons/. The project’s shared models, forms, views and fixture are prerequisites, not a hidden online runtime.
from django.urls import reverse, resolve
path = reverse("workshops:detail", kwargs={"slug":"lamp-care"})
match = resolve(path)
print(path)
print(match.view_name)
print(match.kwargs["slug"])
Expected result
/workshops/lamp-care/ workshops:detail lamp-care
The converter captures the readable slug and reverse produces a path with the expected slash. Nothing has queried the database yet. A matching route can still lead to a 404 if the requested workshop is missing or unpublished.
Use Django’s versioned official documentation for exact API contracts and the deployment checklist before a separate release.