gpt4 book ai didi

django - 奇怪的模板包含并扩展了 Django 中的行为

转载 作者:行者123 更新时间:2023-12-02 05:59:00 25 4
gpt4 key购买 nike

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

因此假设我们有一个 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 时,我希望得到如下内容:

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

但奇怪的是我得到的总是:

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

到底为什么会发生这种情况?

最佳答案

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

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

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

[编辑]这个bug看起来在最新的0.8.4版本中已经被修复了,而且在0.8.3的时候它一直困扰着我。

关于django - 奇怪的模板包含并扩展了 Django 中的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4201840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com