About Lesson
URL Dispatcher and Patterns
Django’s URL dispatcher maps URLs to specific views. This is managed in the urls.py
file.
- Define URL Patterns: In the project’s
urls.py
: - Create App URLs: In the app directory (
myapp
), create aurls.py
file:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('myapp/', include('myapp.urls')), # Include app-specific URLs
]
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
Join the conversation