Template Inheritance with extends and block
Build a base layout and override sections.
Template Inheritance with extends and block 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.
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.htmlDefine 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.
Frequently asked questions
Is the “Template Inheritance with extends and block” lesson free?
Yes — the full text of “Template Inheritance with extends and block” 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 “Template Inheritance with extends and block”?
Build a base layout and override sections. 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 “Template Inheritance with extends and block” 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
- render() and the Template Context
- Template Tags and Filters
- Template Inheritance with extends and block
- The url Tag and static Tag