[Django]-Django – block tags in included templates don't work – Why?

3πŸ‘

βœ…

This :

{% include 'include.html' %}

is not included in any block, and will not be rendered, as you see in response.

Modify your child.html in that way:

#child.html
{% extends 'parent.html' %}

{% block head %}
Child head 
{% endblock %}

{% block body %}
    {% include 'include.html' %}
{% endblock %}

if you want to define some html in both child.html and in include.html, then you should have:

#child.html
{% extends 'parent.html' %}

....

{% block body %}
    {% include 'include.html' %}
    some child html...
{% endblock %}

and in include.html:

{% block body %}
    {{ block.super }}
    some include html...
{% endblock %}

This will render:

some child html
some include html
πŸ‘€Tisho

Leave a comment