Define a Base Template with Blocks
Create a layout with overridable block regions.
Define a Base Template with Blocks is a free Flask Academy lesson on CoddyKit — lesson 1 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.
Layouts Repeat Everywhere
Every page on your site shares the same header, nav, and footer. Copying that HTML into each template is a maintenance trap. A base template fixes it. 🧩
One Skeleton, Many Pages
A base template holds the full HTML skeleton once. Child pages reuse it and only fill in the parts that differ, so shared markup lives in a single file.
Blocks Mark the Holes
Inside the base, a block marks a region that child pages can override. Everything outside a block is fixed and shared by every page.
Declare a Block
You open a region with a named block tag and close it with endblock. Anything between them is the default content for that slot.
<title>{% block title %}My Site{% endblock %}</title>A Real Base Skeleton
This base.html wraps the doctype, head, and body once. The title and content blocks are the only parts pages will customize.
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}Site{% endblock %}</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>Name Your Blocks Clearly
Give each block a descriptive name like content, title, or sidebar. Child pages reference blocks by that exact name when they override them.
Blocks Can Hold Defaults
Content between the block tags is a default. If a child page does not override the block, the visitor sees this fallback text instead.
{% block footer %}© CoddyKit{% endblock %}Where the Base File Lives
Keep the layout in your templates folder, usually named base.html. Child templates point back to it by this path when they extend it.
Plan Blocks Before Coding
Think about which page areas actually change: title, main body, maybe a sidebar. Each changing area becomes one block in your base layout.
Blocks Can Nest
A block may sit inside another block, like a head block holding a styles block. Nesting lets pages tweak fine details without redefining the whole region.
Less Markup to Maintain
With a base template, updating the nav once changes every page at once. That single source of truth is the whole point of a shared layout. ✨
Quick Check
What is the purpose of a block tag in a base template?
Recap: Base Templates
A base template holds shared markup once and exposes named blocks as customizable slots. Next you will extend this base from child pages. 🎯
Frequently asked questions
Is the “Define a Base Template with Blocks” lesson free?
Yes — the full text of “Define a Base Template with Blocks” 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 “Define a Base Template with Blocks”?
Create a layout with overridable block regions. 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 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Define a Base Template with Blocks” 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