[Answer]-Django static file inheritance

1👍

You don’t need to specify two template directories. There is a concept of parent and child templates. All child templates extends the parent:

base.html (we often use this name for parent)

<html>
    <head>
       <!-- Some css, js stuff goes here-->
       {% block extra_head %}
           <!-- A block where child templates add more css and js stuff if needed -->
       {% endblock extra_head %}
    </head>
    <body>
        {% block body %}
           <!-- body content here -->
        {% endblock body %}
    </body>
</html>

And then child template will extend the base.html as:

child.html

{% extends "base.html" %}

{% block body %}
    <h1>Hello!</h1>
{% endblock body %}

Leave a comment