0 day streak
python / beginner
Snippet

Basic URL Routing

URL patterns map specific URL strings to the view functions that should handle the request.

snippet.py
python
1
2
3
4
5
6
from django.urls import path
from . import views
urlpatterns = [
path('hello/', views.welcome_view, name='hello'),
]
django
Breakdown
1
path('hello/', ...)
The URL path that users will type in their browser (e.g., /hello/).
2
views.welcome_view
The function that Django will execute when this URL is visited.
3
name='hello'
A unique name for this URL, allowing you to reference it elsewhere in your code.