Template inheritance
corebeginner{% extends "base.html" %} (first tag, required) makes a template inherit a parent's structure; {% block name %}...{% endblock %} marks a section the child can override; {% include "x.html" %} renders a separate template in place, independently.
Think of it as
A base template is a printed form with labeled blank sections — {% block %} is the label on each blank. A child template that {% extends %} it fills in only the blanks it cares about; anything it doesn't override falls back to what the base already wrote in that blank. {% include %} is different in kind: it's pasting in a whole separate sheet, rendered on its own, sharing nothing with the including template except the context passed to it.
What we're doing: Extend a shared base template, override one block, and reuse the parent's content in another via block.super.
- 1
- {% extends %} is the first line, before even a comment — this is enforced, not just convention.
- 4
- {{ block.super }} inserts base.html's own <title> content ("My Site") rather than replacing it entirely, so the page title becomes "Article Name — My Site".
Why this works: Overriding a block replaces it completely by default — {{ block.super }} is the specific escape hatch for when a child wants to ADD to the parent's content rather than fully replace it, exactly like this title block combining the article name with the site's own base title.
Putting content before {% extends %}
Wrong
Better
What you see: TemplateSyntaxError: 'extends' cannot appear more than once in the same template, or the extends tag is silently ignored and the child renders as a standalone page instead of inheriting base.html.
Why: {% extends %} is documented to be the first tag in the template with nothing preceding it, including comments — Django's template parser uses this positional rule to recognize an inheriting template at all, rather than scanning the whole file for the tag.
- base.html — defines {% block content %}default{% endblock %}
- child.html — {% extends "base.html" %}, does not override content
- Rendered output — shows "default" — the parent's own block content
Inheritance vs. inclusion
Together
Remember: {% extends %} must be the first tag; a block not overridden falls back to the parent's content; {{ block.super }} adds to it instead of replacing it; {% include %} renders a separate template independently, sharing context by default.
See also: templates · autoescaping and safe strings

