Weird template includes and extends behavior in Django

Gurus, I searched this problem many times, but I could not find useful information.

Suppose we have a template base.html:

{% block test %}This is the base!{% endblock %}

And 2 child patterns under this, a.htmlandb.html

a.html:

{% extends "base.html" %}
{% block test %}This is the A!{% endblock %}

b.html

{% extends "base.html" %}
{% block test %}This is the B!{% endblock %}

Now we have the 4th template as root.html

<html>
    <body>
        {% include 'a.html' %}
        {% include 'b.html' %}
        {% include 'base.html' %}
    </body>
</html>

So, when I do root.html rendering, I expect to get sth like:

This is A! This is B! This is the base!

But it’s strange what I got, always:

This is A! This is A! This is A!

Why is this exactly happening?

+3
source share
1 answer

OK, I think I found the main reason: the djang debug_toolbars plugin. As soon as I turn it off in settings.py everything works fine ...

, , .

, , .

[EDIT] 0.8.4, 0.8.3 .

+2

Source: https://habr.com/ru/post/1775354/


All Articles