Template inheritance keeps repeated page structure in one parent template. Child templates extend that parent and fill only the named blocks they need, so a site-wide change can reach many pages without copy-and-paste surgery. section 3.0 section 3.10
A Django inheritance hierarchy works like this:
- Create a base template such as base.html containing the shared HTML structure and placeholder blocks. section 3.8 section 3.8.1
- Mark replaceable regions with paired {% block name %} and {% endblock %} tags. section 3.8
- Begin a child with {% extends "base.html" %}; matching child blocks replace the parent blocks while the rest of the structure remains inherited. section 3.8 section 3.8.1
- Point the view’s render() call at the child template, then request the page to see the inherited result. section 3.8.1
A smaller News page
base.html defines title and content blocks. news2.html extends it, changes the title with {{ block.super }}: News, and supplies a News heading plus a loop over news items. The view renders news2.html, while styling added to base.html applies to every inheriting template. section 3.8.1
Figure 3.4 Page inheritance for component reuse
Use the inheritance hierarchy to visualize how a base page can pass structure through intermediate layouts to a concrete page. section 3.8


