0 day streak
python / beginner
Snippet

URL Path Converters

URL path converters allow you to capture specific types of data (like integers or strings) directly from the URL and pass them as arguments to your view functions.

snippet.py
python
1
2
3
4
5
6
from django.urls import path
from . import views
urlpatterns = [
path('article/<int:article_id>/', views.article_detail),
]
django
Breakdown
1
path('article/<int:article_id>/', ...)
Defines a URL pattern that looks for the string 'article/' followed by a value.
2
<int:article_id>
The converter 'int' ensures the captured segment is a number, saving it to the variable 'article_id'.