Writing redundant HTML boilerplate across dozens of views—such as repetitive <head> tags, navigation bars, CSS stylesheets, and footers—violates the Don't Repeat Yourself (DRY) principle. Django's Template Inheritance solves this using a skeleton layout architecture with overridable {% block %} sections.
base.html)Create a master layout defining the site-wide HTML skeleton and content slots:
Child templates declare which base template they inherit from using {% extends %} as the very first line:
{{ block.super }}If you want to append content to a block rather than completely overwriting it, use {{ block.super }}:
{% include %}For repeated UI fragments (like an article card or pagination bar), use {% include %}:
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Template Engine Basics | Function-Based Views (FBV) |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.