0Pricing
Django Academy · Aula

Capturando Parâmetros de URL

Leia conversores de caminho, como int e slug, nas views

Capturando Parâmetros de URL é uma aula grátis de Django Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Django Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Django Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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. ✨

Perguntas Frequentes

A aula “Capturando Parâmetros de URL” é grátis?

Sim — o texto completo de “Capturando Parâmetros de URL” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Django Academy, atualize para CoddyKit PRO. O curso de Django Academy inclui 4 aulas no total.

O que vou aprender em “Capturando Parâmetros de URL”?

Leia conversores de caminho, como int e slug, nas views Você pratica Django Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Django Academy?

Nenhuma experiência prévia é necessária. Django Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.

Quanto tempo leva a aula “Capturando Parâmetros de URL”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Django Academy?

Sim. Cada aula de Django Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Escrevendo uma View Baseada em Função
  2. Padrões de URL com path()
  3. Capturando Parâmetros de URL
  4. Incluindo URLs de Aplicativos e Nomeando Rotas
← Voltar para Django Academy