1

I have the following setup.

base.html

<html>
 //etc
<body>
    {% include "partials/footer.html" %}
</body>
</html>

partials/footer.html

<div class="footer">
    <h2>{% block footer_headline %}Default footer headline{% endblock %}</h2>
</div>

page1.html

{% extends 'base.html' %}
{% block footer_headline %}NEW Footer Headline {% endblock %}

However, the footer headline does not change. What am I doing wrong?

1 Answer 1

6

This is a documented limitation. See the documentation: https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#include

The include tag should be considered as an implementation of “render this subtemplate and include the HTML”, not as “parse this subtemplate and include its contents as if it were part of the parent”. This means that there is no shared state between included templates – each include is a completely independent rendering process. Blocks are evaluated before they are included. This means that a template that includes blocks from another will contain blocks that have already been evaluated and rendered - not blocks that can be overridden by, for example, an extending template.

The simplest solution is to not include templates that contain blocks you wish to overwrite. Just put the footer markup in the base.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.