← Django learning pathDjango · Module 2 of 10
URLs and views
Map URLs to Python functions that return responses.
📖 Key ideas
- A view is a function taking request and returning HttpResponse.
- urls.py maps paths: path("about/", views.about).
- Include app URLs: path("blog/", include("blog.urls")).
- Path converters: path("post/<int:id>/", views.post).
- Class-based views (ListView, DetailView) reduce repetition.
💡 Real-life example: urls.py is a building directory board; views are the offices people are sent to.
ViewFunction or class handling a request
urls.pyURL patterns file
path()Maps a route to a view
include()Adds another URL file