0Pricing
Django Academy · Lesson

Including App URLs and Naming Routes

Use include() and name routes for reverse().

Including App URLs and Naming Routes is a free Django Academy lesson on CoddyKit — lesson 4 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.

Two Levels of URLs

Django splits routing into the project's urls.py and each app's own. The project includes app URLs to keep things tidy.

Why Apps Get Their Own urls.py

Giving each app its own URL file keeps routes reusable and self-contained. You can drop an app into any project cleanly.

Importing include

To delegate to an app, you use include. Import it alongside path from django.urls in the project file.

from django.urls import path, include

Wiring Up include()

In the project urls.py, point a prefix at an app's URL module with include. All its routes hang under that prefix.

path('blog/', include('blog.urls'))

How Prefixes Combine

The project prefix joins the app route. So blog/ plus an app route of post/ serves the full path blog/post/.

Naming a Route

Give each route a name so you never hardcode its URL. You refer to the route by this stable name everywhere else.

path('about/', views.about, name='about')

Why Names Beat Hardcoding

If a URL changes, hardcoded links break. A named route lets you change the path once and every link still works.

reverse() in Python

Use reverse to build a URL from a route name in your view code. Django returns the current path for that name.

from django.urls import reverse
url = reverse('about')

app_name and Namespaces

Set app_name in an app's urls.py to namespace its routes. Then names look like blog:detail, avoiding clashes between apps.

app_name = 'blog'

Referencing Namespaced Routes

With a namespace set, you reference routes as namespace:name. This keeps blog:detail and shop:detail clearly separate.

reverse('blog:detail')

The redirect Shortcut

The redirect helper also accepts a route name. Send users somewhere by name instead of a fragile literal path.

from django.shortcuts import redirect
return redirect('about')

Quick Check

Recall what include() does in the project's urls.py.

Recap: Include and Name

Use include to mount app URLs under a prefix, and name routes so reverse and redirect stay solid when paths change. 🧭

Frequently asked questions

Is the “Including App URLs and Naming Routes” lesson free?

Yes — the full text of “Including App URLs and Naming Routes” 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 “Including App URLs and Naming Routes”?

Use include() and name routes for reverse(). 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 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Including App URLs and Naming Routes” 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

  1. Writing a Function-Based View
  2. URL Patterns with path()
  3. Capturing URL Parameters
  4. Including App URLs and Naming Routes
← Back to Django Academy