Template inheritance
Template inheritance is a templating pattern in which child templates reuse and extend a shared parent template by filling or overriding defined sections.
The Well-Grounded Python Developer: How the pros use Python and Flask
Template inheritance is a templating pattern in which a child template extends a parent template and overrides or fills named sections.
- How it is used
- Reuses shared HTML structure across web pages instead of copying banners, footers, and boilerplate.
- How deep it goes
- Shows a parent layout with named blocks and a child that extends it; does not explore inheritance edge cases.
- Examples
- Uses a home page with a shared banner and footer, plus a content block showing time, visits, and banner colors.
- What you can do after
- Apply it via Jinja2 to separate a shared page layout from page-specific content.
Go in Practice, Second Edition
Template inheritance is a composition pattern in which an extending template fills or overrides sections defined by a shared base template.
- How it is used
- Shares a top-level HTML layout across pages while allowing page-specific sections to fill or override it.
- How deep it goes
- Works through base and extending templates, directives, and Go setup; stops short of claiming full template-system inheritance.
- Examples
- Demonstrates a user page and a general page, including an optional styles override.
- What you can do after
- Build it from scratch with html/template by pairing a base with page-specific definitions and executing the named template.
Read how Go in Practice, Second Edition explains template inheritance →
Django in Action
Template inheritance is a templating technique in which a child template extends a parent template and overrides or fills its defined blocks.
- How it is used
- Organizes repeated HTML structure across Django pages while keeping individual page templates short.
- How deep it goes
- Explains named blocks, parent-child hierarchy, overrides, view selection, and shared styling without descending into template-engine internals.
- Examples
- Uses RiffMates base.html and news2.html to demonstrate title overrides, content blocks, news loops, and shared styling.
- What you can do after
- Apply it via Django templates to build reusable page layouts and override only page-specific regions.
Related concepts
- block directiveuses · A block directive defines a template section with default content and immediately executes that section when invoked.
- templateuses · A template is a reusable structure with fixed elements and variable parts for creating or generating similar content, outputs, or artifacts.
- inheritanceequivalent to · Inheritance is a mechanism by which a child type or element receives properties, values, or behavior from a parent, subject to system rules and possible overrides.
- html/template packageused by · The Go html/template package parses and executes HTML templates with data substitutions, control logic, and contextual escaping of HTML-sensitive content.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


