liveBook · Manning

Template block

A template block is a named region in a template that a child template can fill or override.

How 2 Manning books explain it

The Well-Grounded Python Developer: How the pros use Python and Flask

A template block is a named region in a Jinja2 template that can be defined by a parent and filled or overridden by a child.

How it is used
Organizes shared Flask page layout and page-specific content through parent and child Jinja2 templates.
How deep it goes
Defines block syntax and demonstrates parent and child templates, without detailing template-rendering internals.
Examples
Uses a shared page template and a child displaying time, visit counts, and banner colors.
What you can do after
Build it from scratch: separate shared page structure from content supplied by a child template.

Read how The Well-Grounded Python Developer: How the pros use Python and Flask explains template block →

Django in Action

A template block is a named section of a template delimited by paired template tags that can be replaced by a child template.

How it is used
Composes reusable Django pages by centralizing shared HTML and replacing named sections in child templates.
How deep it goes
Defines block syntax, inheritance, named closing tags, block.super, and a working view-template update.
Examples
Uses RiffMates base.html and news2.html to demonstrate title and content overrides, loops, and inherited content.
What you can do after
Apply Django template inheritance to build shorter pages that share structure and site-wide styling.

Read how Django in Action explains template block →

Related concepts

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.