奇怪的模板包含并扩展了 Django 中的行为
大师们, 我在这个问题上搜索了很多次,但几乎找不到任何有用的信息。
因此,假设我们有一个 base.html
模板:
{% block test %}This is the base!{% endblock %}
以及其下的 2 个子模板,a.html
和 b.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 %}
现在我们有第四个模板作为 root.html
<html>
<body>
{% include 'a.html' %}
{% include 'b.html' %}
{% include 'base.html' %}
</body>
</html>
因此,当我渲染 root.html 时,我期望得到如下内容:
这是A!这是B!这是基地!
但奇怪的是我得到的总是:
这是A!这是A!这是A!
究竟为什么会发生这种情况?
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.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我想我找到了根本原因:djang debug_toolbars 插件。
一旦我在 settings.py 中禁用它,那么一切都会正常...
这很奇怪,但我想我会发布插件的问题跟踪列表。
希望这可以帮助遇到同样问题的人
[编辑]
这个bug看起来在最新的0.8.4版本中已经被修复了,而且在0.8.3的时候它一直困扰着我。
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.