liveBook · Manning

Base template

As explained in Django in Action

A parent template is a template whose structure and blocks are inherited by another template.

A base template is the parent page for a site. It holds shared HTML—such as the document structure, navigation, footer, and styling hooks—while named blocks mark the parts child templates can replace. In Django, a child template uses {% extends "base.html" %} and overrides matching {% block %} regions. section 3.8 section 3.8.1

A practical inheritance arrangement works like this:

  • Create base.html with common HTML and blocks such as title and content. section 3.8.1
  • Extend the base from a page such as news2.html, then define only the blocks that need different content. section 3.8.1
  • Use {{ block.super }} when a child should add to the parent block instead of replacing it. section 3.8.1
  • Point the view at the new child template, run the development server, and revisit the URL to verify the result. section 3.8.1

RiffMates page inheritance

base.html defines a title block defaulting to “RiffMates” and an empty content block. news2.html extends it, changes the title to “RiffMates: News” with {{ block.super }}, and supplies an h1 plus a news list. Shared styling added to base.html then applies to every inheriting page. section 3.8.1

Figure 3.4 Page inheritance for component reuse
figure

A hierarchy can layer variations: a main page, a navigation-enabled parent, and concrete site pages. section 3.8

How Django in Action covers it

How deep it goes
Defines blocks, extends, block.super, file placement, view changes, and browser verification without descending into template-engine internals.
Examples
Uses RiffMates base.html and news2.html, including title, content, block.super, an h1, and a rendered news list.
What it assumes
Assumes basic HTML and Django views while teaching template blocks, extends, parent structure, and shared styling from working examples.
What you can do after
Apply it via Django templates to build child pages that inherit shared structure and selectively override or extend blocks.
How it connects
Connects template inheritance with template blocks, child templates, views, and reusable web components.

Also explained in

Compare how 2 books explain base template →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.