0
0
Djangoframework~15 mins

Why URL configuration matters in Django - See It in Action

Choose your learning style9 modes available
Why URL configuration matters
📖 Scenario: You are building a simple Django website for a local bookstore. The website needs to show a homepage and a page listing books. To make sure visitors can reach these pages by typing the right web addresses, you need to set up URL configuration correctly.
🎯 Goal: Learn how to create URL patterns in Django that connect web addresses to the right views, so the website shows the correct pages when users visit specific URLs.
📋 What You'll Learn
Create a Django URL configuration list named urlpatterns
Add a URL pattern for the homepage at path '' linked to a view named home_view
Add a URL pattern for the books page at path 'books/' linked to a view named books_view
Use the path function from django.urls to define URL patterns
💡 Why This Matters
🌍 Real World
Every Django website needs URL configuration to map web addresses to the right pages so visitors can navigate the site easily.
💼 Career
Understanding URL configuration is essential for Django developers to build functional web applications that respond correctly to user requests.
Progress0 / 4 steps
1
Set up URL patterns list
Create an empty list called urlpatterns to hold your URL patterns.
Django
Need a hint?

Think of urlpatterns as a list where you will add all your web address rules.

2
Import the path function
Add an import statement to bring in the path function from django.urls.
Django
Need a hint?

You need path to define URL patterns easily.

3
Add homepage URL pattern
Add a URL pattern to urlpatterns for the homepage at path '' that uses the view function home_view.
Django
Need a hint?

Use path('', home_view) to connect the homepage URL to the view.

4
Add books page URL pattern
Add another URL pattern to urlpatterns for the books page at path 'books/' that uses the view function books_view.
Django
Need a hint?

Remember to add a trailing slash in the path string for the books page.