Django Academy · Aula

A Tag url e a Tag static

Vincule rotas e recursos sem codificar caminhos diretamente

Aula 4 de 413 etapas

A Tag url e a Tag static é uma aula grátis de Django Academy no CoddyKit. Esta é a aula 4 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.

Never Hardcode Paths

Typing URLs and file paths by hand breaks the moment they change. Django gives you the url and static tags to build them safely. 🔗

The url Tag Builds Routes

The url tag turns a route name into its real path. Rename the URL pattern later and every link updates automatically.

<a href="{% url 'home' %}">Home</a>

Name Your Routes First

For url to work, give each pattern a name in urls.py. That name is the stable handle the template refers to.

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

Passing URL Arguments

If a route needs a value, pass it after the name. Django slots the argument into the path where the converter expects it.

{% url 'post_detail' post.id %}

Namespaced URL Names

When an app sets an app_name, reference routes with a prefix like blog:detail to avoid clashing with other apps.

{% url 'blog:detail' post.id %}

The static Tag for Assets

The static tag builds the correct URL to a CSS, JS, or image file, even when storage paths differ in production.

{% static 'css/style.css' %}

Load static First

Before using the tag you must load static near the top of the template, which pulls the tag into that file.

{% load static %}

Linking a Stylesheet

Combine the pieces to link a stylesheet the safe way, so the path stays valid no matter where files are served from.

<link rel="stylesheet" href="{% static 'css/style.css' %}">

Showing an Image

The same static tag works for images. Point it at a file under your static folder and Django resolves the full URL.

<img src="{% static 'img/logo.png' %}">

Why static Matters

In production, assets often move to a CDN or hashed path. The static tag hides that, so your templates never need editing.

Two Tags, One Goal

Both tags share a purpose: let Django compute paths so you do not. Use url for views and static for files.

Quick Check

Pick the right tag for the right job.

Recap: Safe Links

You learned to build view paths with the url tag and asset paths with static, after loading static. That wraps up rendering HTML with data.

Grátis para começar

Aprenda Python com um tutor de IA — grátis

Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.

Cursos
30
Aulas
120

Perguntas Frequentes

A aula “A Tag url e a Tag static” é grátis?

Sim — o texto completo de “A Tag url e a Tag static” é 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 “A Tag url e a Tag static”?

Vincule rotas e recursos sem codificar caminhos diretamente 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 4 de 4.

Quanto tempo leva a aula “A Tag url e a Tag static”?

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. render() e o Contexto do Template
  2. Tags e Filtros de Template
  3. Herança de Templates com extends e block
  4. A Tag url e a Tag static
← Voltar para Django Academy