0
0
Djangoframework~20 mins

Including app URLs in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Including app URLs in a Django project
📖 Scenario: You are building a Django website with multiple apps. Each app has its own URLs. You want to connect these app URLs to the main project so the website works correctly.
🎯 Goal: Learn how to include app URLs inside the main project's URL configuration using Django's include() function.
📋 What You'll Learn
Create a Django project-level urls.py file
Create an app-level urls.py file with URL patterns
Use include() to connect app URLs in the project URLs
Use exact variable and function names as instructed
💡 Why This Matters
🌍 Real World
In real Django projects, apps have their own URLs. Including them in the main project URLs keeps code organized and modular.
💼 Career
Understanding how to include app URLs is essential for Django web developers to build scalable and maintainable websites.
Progress0 / 4 steps
1
Create app-level URLs
Create a file called urls.py inside the app folder. Define a variable called app_name and set it to 'blog'. Then create a list called urlpatterns with one URL pattern: path '' mapped to a view function called home.
Django
Need a hint?

Use app_name = 'blog' and urlpatterns = [path('', views.home, name='home')].

2
Create project-level URLs
In the project folder, open urls.py. Import path and include from django.urls. Create a list called urlpatterns but leave it empty for now.
Django
Need a hint?

Import include and create urlpatterns = [].

3
Include app URLs in project URLs
Add a path to urlpatterns that uses path('blog/', include('blog.urls')) to include the app URLs under the /blog/ URL prefix.
Django
Need a hint?

Use path('blog/', include('blog.urls')) inside urlpatterns.

4
Complete project URLs with admin path
Add the Django admin path path('admin/', admin.site.urls) to urlpatterns. Import admin from django.contrib at the top.
Django
Need a hint?

Import admin and add path('admin/', admin.site.urls) to urlpatterns.