【问题标题】:Weird template include and extends behavior in Django奇怪的模板包含和扩展 Django 中的行为
【发布时间】:2010-11-17 05:46:01
【问题描述】:

大师们, 我在这个问题上搜索了很多次,但我几乎找不到任何有用的信息。

所以假设我们有一个base.html 模板:

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

还有 2 个子模板,a.htmlb.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!

为什么会发生这种情况?

【问题讨论】:

    标签: django templates include extends


    【解决方案1】:

    好的,我想我找到了根本原因:djang debug_toolbars 插件。 一旦我在 settings.py 中禁用它,一切都会正常运行...

    这很奇怪,但我想我会将问题发布在插件的问题跟踪列表中。

    希望这可以帮助遇到同样问题的人

    [编辑] 这个错误似乎在最新的 0.8.4 修订版中得到了修复,而在 0.8.3 的时候它一直困扰着我。

    【讨论】:

      猜你喜欢
      • 2010-11-27
      • 2011-08-06
      • 1970-01-01
      • 2019-03-05
      • 2019-04-21
      • 1970-01-01
      • 2012-12-10
      • 2012-04-17
      • 1970-01-01
      相关资源
      最近更新 更多