URL Parameters
Angle brackets capture parts of the URL. Converters such as int, str, slug and uuid control the type. The value is passed to the view as an argument.
Example
# urls.py
path("post/<int:post_id>/", views.detail, name="detail"),
path("tag/<slug:name>/", views.tag, name="tag"),
# views.py
def detail(request, post_id):
return HttpResponse(f"Post {post_id}")Exercise
Capture an integer.
path("post/<:id>/", view)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.