0Pricing
Django Academy · Lesson

Capturing URL Parameters

Read path converters like int and slug into views.

Capturing URL Parameters is a free Django Academy lesson on CoddyKit — lesson 3 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.

Why Capture Parameters

Many pages depend on a value in the URL, like a product id. Django lets you capture that value and pass it straight to your view.

Angle Bracket Syntax

You capture a piece of the URL with angle brackets. Whatever is inside becomes a named argument for your view.

path('post/<int:id>/', views.detail)

Converters Set the Type

The word before the colon is a converter. It both matches a pattern and converts the captured text to the right Python type.

The int Converter

The int converter matches digits and hands your view a real integer, not a string. Perfect for numeric ids.

path('post/<int:id>/', views.detail)

The slug Converter

The slug converter matches letters, numbers, hyphens, and underscores. It is ideal for readable, SEO-friendly URLs.

path('blog/<slug:title>/', views.post)

The View Receives the Value

The captured name becomes a parameter in your view, right after request. The names must match exactly.

def detail(request, id):
    return HttpResponse('Post ' + str(id))

Names Must Match

The name in the URL and the view argument must be identical. If the URL says id, your view must accept id too.

More Built-in Converters

Beyond int and slug, Django ships str, uuid, and path converters. Each matches a different shape of value.

str Is the Default

If you skip the converter, Django uses str. It matches any text except a slash, which keeps segments separate.

path('user/<username>/', views.profile)

Capturing Multiple Values

You can capture several values in one route. Each becomes its own keyword argument in the view, in order.

path('<int:year>/<int:month>/', views.archive)

Wrong Type, No Match

If a URL value does not fit the converter, the route simply does not match. Django moves on or returns a 404.

Quick Check

Consider which converter fits a numeric id.

Recap: Dynamic URLs

Use angle brackets with a converter to capture URL values. The view receives them by name, typed and ready to use. ✨

Frequently asked questions

Is the “Capturing URL Parameters” lesson free?

Yes — the full text of “Capturing URL Parameters” 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 “Capturing URL Parameters”?

Read path converters like int and slug into views. 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 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Capturing URL Parameters” 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