1.Template inheritance
{% 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.
Key features
- {% extends %} must be the very first tag in the child template — nothing, not even a comment, before it
- A block not overridden in the child renders whatever the parent put inside it
- {{ block.super }} inside an overriding block inserts the parent's version of that same block, instead of replacing it entirely
- {% include "x.html" %} renders independently — it does not participate in the extends/block chain at all
- {% include "x.html" with name="Jane" only %} passes a scoped context; without only, the including template's full context is still visible
Inheritance vs. inclusion
- 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
Command
{% extends "base.html" %}
{% block content %}
{% include "articles/_comment_list.html" with comments=article.comments %}
{% endblock %}{% 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.