URL parameter type converters help Django understand what kind of data to expect in a URL. This makes your web app handle URLs more safely and clearly.
URL parameter type converters in Django
path('route/<converter:name>/', view_function, name='route_name')
The converter tells Django what type to expect (like int, str, slug, uuid, or path).
The name is the variable name your view will receive.
id from the URL and passes it to the view.path('article/<int:id>/', views.article_detail, name='article_detail')
username.path('user/<slug:username>/', views.user_profile, name='user_profile')
file_path.path('files/<path:file_path>/', views.show_file, name='show_file')
order_id.path('order/<uuid:order_id>/', views.order_detail, name='order_detail')
This Django URL pattern uses an int converter to get an article ID from the URL. The view shows the ID in the response.
from django.urls import path from django.http import HttpResponse def show_article(request, id): return HttpResponse(f"Article ID is {id}") urlpatterns = [ path('article/<int:id>/', show_article, name='show_article'), ]
If the URL part does not match the converter type, Django returns a 404 error automatically.
You can create custom converters if needed by defining a class with regex, to_python(), and to_url() methods.
The str converter matches any text except slashes, so it is the default if no converter is given.
URL parameter type converters tell Django what kind of data to expect in URLs.
They help validate and convert URL parts automatically before your view runs.
Common converters include int, str, slug, uuid, and path.