Search code examples
pythondjangodjango-templatesjinja2

footer.html is not included when extending the base.html file


In header.html, I have

<h1>Header Section</h1>

In footer.html, I have

<h1>Footer Section</h1>

In base.html I have

{% include 'header.html'%}
{% block content %} 
{% endblock %}
{% include
'footer.html' %}

But when I extend the base template, I only get the header and the content of the page which extends the base. The footer section appears as {% include 'footer.html' %}

Why is that?


Solution

  • Don't use multiple lines. The Django template engine can not parse this (properly). Put the entire {% include … %} [Django-doc] template tag on a single line:

    {% include 'header.html'%}
    {% block content %} 
    {% endblock %}
    {% include 'footer.html' %}