0
0
Djangoframework~20 mins

urlpatterns list structure in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Building a Django urlpatterns List
📖 Scenario: You are creating a simple Django web application. You need to define URL patterns that connect web addresses to views so users can navigate your site.
🎯 Goal: Build a urlpatterns list in Django that maps specific URL paths to their corresponding view functions.
📋 What You'll Learn
Create a list called urlpatterns
Include exact URL patterns using path() for given routes
Use the exact view function names provided
Import necessary functions and views correctly
💡 Why This Matters
🌍 Real World
Django URL patterns connect web addresses to the code that runs when users visit those addresses. This is essential for building any web app.
💼 Career
Understanding how to define and organize URL patterns is a key skill for Django developers working on real websites and web services.
Progress0 / 4 steps
1
Import path and create an empty urlpatterns list
Write the import statement to import path from django.urls. Then create an empty list called urlpatterns.
Django
Need a hint?

Use from django.urls import path to import the path function.

Create urlpatterns as an empty list.

2
Import the views module
Add an import statement to import the views module from the current package.
Django
Need a hint?

Use from . import views to import views from the current directory.

3
Add URL patterns for home and about pages
Add two path() entries to the urlpatterns list: one for the empty string '' mapped to views.home, and one for 'about/' mapped to views.about.
Django
Need a hint?

Use path('', views.home) for the home page.

Use path('about/', views.about) for the about page.

4
Add URL pattern for contact page with a name
Add a path() entry to urlpatterns for the URL 'contact/' mapped to views.contact and give it the name 'contact'.
Django
Need a hint?

Use the name argument in path() to name the URL pattern.