A capture specifier is angle-bracket URL syntax that captures part of a path and passes it to a view. It declares both the value's type and the argument name: <int:musician_id> captures an integer named musician_id. section 4.6.1
Common capture types include:
- str captures any non-empty string except the forward-slash path separator. section 4.6.1
- int captures an integer and lets Django cast the URL text before calling the view. section 4.6.1
- slug captures letters, numbers, and hyphens. section 4.6.1
Routing a musician detail page
Register path('musician/<int:musician_id>/', views.musician, name="musician"). Django matches the numeric URL component, passes musician_id to the view, and rejects a non-integer URL as a 404 before the view runs. The view can then retrieve the Musician object and render its template. section 4.6.1
