Django template inheritance allows you to reuse a common layout across multiple pages using {% extends %} and {% block %}.
The {% extends %} tag loads a parent template, while {% block %} defines replaceable sections.
// Child template inheriting base.html
{% extends "base.html" %}
// Base template with a content block
<html>
<body>
<header>Header Content</header>
{% block content %}
<p>Default content for the page</p>
{% endblock %}
<footer>Footer Content</footer>
</body>
</html>
// Overriding the content block
{% extends "base.html" %}
{% block content %}
<p>This is custom content for the child template.</p>
{% endblock %}
Switch between views to see how the blocks are injected.
Default content for the page
{% endblock %}The base template provides structure, and child templates inject only the required content, improving maintainability.