Extend the Base in Child Pages
Use extends and fill blocks per page.
Extend the Base in Child Pages is a free Flask Academy lesson on CoddyKit — lesson 2 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 Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Connect a Page to the Base
A child page does not repeat the skeleton. It declares that it extends the base, then fills only the blocks it needs to change. 🔗
The extends Tag
The first line of a child template uses extends to name its parent layout. This tells Jinja2 to inherit the base before rendering.
{% extends "base.html" %}extends Must Come First
The extends tag has to be the very first thing in the child file. Putting markup above it breaks inheritance and raises a template error.
Override a Block
To replace a slot, redeclare the block with the same name in the child. Whatever you put inside now shows instead of the base default.
{% block title %}Dashboard{% endblock %}A Complete Child Page
This child template extends base.html and overrides two blocks. The rest of the page comes straight from the parent layout.
{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block content %}
<h1>Welcome</h1>
{% endblock %}Skip Blocks You Like
You only override the blocks you want to change. Any block you leave out keeps the default content defined in the base template.
Reuse Parent Content
Inside an overridden block you can call super() to pull in the parent block content, then add your own around it.
{% block content %}{{ super() }}<p>Extra</p>{% endblock %}Render the Child, Not the Base
Your view returns the child template path. Flask renders the child, which inherits the base, so you never call base.html directly.
return render_template("home.html")Block Names Must Match
Override only works when the child block name exactly matches one in the base. A typo silently leaves the parent default in place.
One Base, Many Children
Dozens of pages can extend the same base.html. Each child stays tiny because it only carries the markup unique to that page.
Inheritance Saves You
Change the base header once and every child page updates instantly. That cascade is the real power of template inheritance. 🚀
Quick Check
Where must the extends tag appear in a child template?
Recap: Extending Pages
Child pages extend a base, override matching blocks, and may reuse parent content with super(). One base now powers many pages. 🎯
Frequently asked questions
Is the “Extend the Base in Child Pages” lesson free?
Yes — the full text of “Extend the Base in Child Pages” is free to read here on the web, and the Flask 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 Flask Academy course, upgrade to CoddyKit PRO.
What will I learn in “Extend the Base in Child Pages”?
Use extends and fill blocks per page. You practise Flask 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 Flask Academy?
No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Extend the Base in Child Pages” 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 Flask Academy lesson?
Yes. Every Flask 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
- Define a Base Template with Blocks
- Extend the Base in Child Pages
- Include Reusable Partials
- Macros for Repeated Markup