URL Patterns with path()
Connect a URL to a view in urls.py.
URL Patterns with path() is a free Django Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why URLs Need Mapping
Django needs to know which view handles which address. The URLconf is the map that connects a URL to a view.
The urls.py File
Your URL map lives in urls.py. It holds a list called urlpatterns that Django checks top to bottom for a match.
Importing path
The main tool for routing is the path function. Import it from django.urls at the top of the file.
from django.urls import pathAnatomy of path()
The path function takes a route string and the view to call. You list these inside the urlpatterns list.
path('about/', views.about)A Complete urlpatterns
Here is a working map. The urlpatterns list ties the about/ route to the about view function.
from django.urls import path
from . import views
urlpatterns = [
path('about/', views.about),
]Pass the View, Don't Call It
Write views.about without parentheses. Django calls the view for you when the route matches a request.
The Empty Route
An empty string route, '', matches your site's root. It is how you point the home page at a view.
path('', views.home)Trailing Slashes Matter
Django routes usually end with a slash, like about/. This is a strong convention, so keep it consistent across routes.
Order Decides the Match
Django reads urlpatterns top to bottom and stops at the first match. Put more specific routes above broader ones.
Importing Your Views
Bring your views into urls.py first. The import line lets you reference each view by name in path calls.
from . import viewsWhat Happens on No Match
If no pattern matches the request, Django returns a 404 error. That is your signal to add or fix a route.
Quick Check
Think about how you reference a view inside path().
Recap: You Mapped a URL
In urls.py you import path, list routes in urlpatterns, and point each one at a view. Order and trailing slashes matter. 🔗
Frequently asked questions
Is the “URL Patterns with path()” lesson free?
Yes — the full text of “URL Patterns with path()” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.
What will I learn in “URL Patterns with path()”?
Connect a URL to a view in urls.py. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Django Academy?
No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “URL Patterns with path()” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Django Academy lesson?
Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Writing a Function-Based View
- URL Patterns with path()
- Capturing URL Parameters
- Including App URLs and Naming Routes