python / beginner
Snippet
Django Template Inheritance
Template inheritance allows you to build a base 'skeleton' template that contains all the common parts of your site and defines blocks that child templates can override.
snippet.py
1
2
3
4
5
{% extends 'base.html' %}{% block content %}<h1>Welcome to my site!</h1>{% endblock %}
django
Breakdown
1
{% extends 'base.html' %}
Tells Django that this template is a child of base.html and inherits its structure.
2
{% block content %}
Defines a section that will replace the corresponding block in the parent template.
3
{% endblock %}
Marks the end of the custom content block.