0Pricing
Django Academy · Aula

Herança de Templates com extends e block

Crie um layout base e substitua seções

Herança de Templates com extends e block é 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.

Stop Repeating Layout

Every page shares a header, nav, and footer. Template inheritance lets you write that shell once and reuse it everywhere. 🧱

Start with a Base

A base template holds the common HTML skeleton. Child pages will plug their unique content into spots you leave open.

base.html

Define a block

A block marks a section a child can replace. You name it, leave optional default content, then close it with endblock.

{% block content %}{% endblock %}

A Minimal Base File

This base wraps a title block and a content block in real HTML. Children will fill those two named holes.

<html><head><title>{% block title %}Site{% endblock %}</title></head>
<body>{% block content %}{% endblock %}</body></html>

Children Use extends

The extends tag must be the first line of a child template. It tells Django which base layout to build upon.

{% extends "base.html" %}

Override a block

In the child you redefine a block with the same name. Whatever you put inside replaces the base default for that page.

{% extends "base.html" %}
{% block content %}<h1>Welcome</h1>{% endblock %}

Unfilled Blocks Use Defaults

If a child skips a block, the base content shows instead. That makes a default a safe placeholder for shared text.

Keep Parent Content with super

Call block.super to keep the parent block content and add your own around it, instead of replacing it entirely.

{% block content %}{{ block.super }}<p>Extra</p>{% endblock %}

Inheritance Can Nest

A child can itself be a base for deeper pages. Layered layouts let sections share a sub-shell while still using the global one.

extends Goes First

Only one extends is allowed and it must lead the file. Anything before it, even a comment, breaks the inheritance.

Blocks Build Pages

Think of a page as a base full of blocks that children fill. This keeps every page consistent and edits in one place.

Quick Check

Recall how a child connects to its layout.

Recap: Write Layout Once

You learned to define blocks in a base and fill them with extends in children, even keeping parent content via block.super. Next: linking routes and assets.

Perguntas Frequentes

A aula “Herança de Templates com extends e block” é grátis?

Sim — o texto completo de “Herança de Templates com extends e block” é 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 “Herança de Templates com extends e block”?

Crie um layout base e substitua seções 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 “Herança de Templates com extends e block”?

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