Skip to content
Learn Netverks

Lesson

Step 14/36 39% through track

urls-routing

URL routing

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches URL routing: the syntax, APIs, and habits you need before advancing in Django.

URL routing and view boundaries organize teams—fat views and circular imports are common learner pitfalls.

You will apply URL routing in contexts like: SaaS dashboards, CMS-style products, internal tools, and APIs paired with React or mobile clients.

Write Python 3 in the editor and click Run on server—the dev runner executes your script; Django framework lessons also use local startproject for full MVT (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Django maps URL paths to views through URLconf modules (urls.py). Clean URLs improve SEO and readability—/articles/5/ beats /article.php?id=5.

Basic patterns

from django.urls import path
from . import views

urlpatterns = [
    path("", views.index, name="index"),
    path("articles/<int:pk>/", views.detail, name="article-detail"),
]

Including app URLs

# project urls.py
path("blog/", include("blog.urls")),

Use {% url 'article-detail' pk=5 %} in templates—never hard-code paths that might change.

Important interview questions and answers

  1. Q: path() vs re_path()?
    A: path() uses simple converters (int, slug, uuid); re_path() uses regex for complex patterns.
  2. Q: Why name URLs?
    A: Reverse resolution decouples templates and redirects from hard-coded paths—rename once in urls.py.
  3. Q: Trailing slash convention?
    A: Django defaults to APPEND_SLASH—/about redirects to /about/ when configured.

Self-check

  1. What does <int:pk> capture?
  2. How do templates link to named URLs?

Interview prep

Why name URLs?

Named URLs enable {% url %} and reverse() without hard-coded paths—rename once in urls.py when routes change.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • path vs re_path?
  • include() when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump