开发者

Weird template include and extends behavior in Django

开发者 https://www.devze.com 2023-01-26 00:43 出处:网络
Gurus, I googled so many times on this issue but I can barely find any useful information. So assume that we have a base.html template as:

Gurus, I googled so many times on this issue but I can barely find any useful information.

So assume that we have a base.html template as:

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

And 2 child templates under that, a.html and b.html

a.html:

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

b.html

{% extends "base.开发者_Python百科html" %}
{% block test %}This is the B!{% endblock %}

Now we have 4th template as root.html

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

So when I render the root.html, I expects to get sth like:

This is the A! This is the B! This is the Base!

But strangely what I got is always:

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

Why exactly is this happening?


OK, I guess I found the root cause: djang debug_toolbars plugin. Once I disable it in the settings.py then everything works just fine...

This is weird but I guess I would post the issue the plugin's issue tracking list.

Hopefully this could help whoever had the same problem

[EDIT] This bug looks like being fixed in the latest 0.8.4 revision, and it was bugging me so much in the 0.8.3 time.

0

精彩评论

暂无评论...
验证码 换一张
取 消