gpt4 book ai didi

python - 为什么我会得到无效的 block 标记 : 'static' error?

转载 作者:行者123 更新时间:2023-11-28 21:51:53 24 4
gpt4 key购买 nike

这是我的 base.html 的头部:

{% load staticfiles %}

<head>

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- the CSS for Foundation - Base of client side -->
<link rel="stylesheet" href="{% static 'css/foundation.css' %}" />

<!-- the CSS for Smooth Div Scroll -->
<link rel="Stylesheet" type="text/cs' %}" href="{% static 'top_scroll/css/smoothDivScroll.css' %}" />

<!-- the CSS for Custom -->
<link rel="stylesheet" href="{% static 'css/custom.css' %} />

<script src="{% static 'js/vendor/modernizr.js' %}"></script>
</head>`

这部分是正文,上面的静态文件加载正确,我在正文中有一些我也想加载的图像,它们位于同一个文件夹中,但我将代码写在另一个文件中并使用{% include "images.html" %}将它们添加到基础。

例如。 <img src="{% static 'top_scroll/images/demo/field.jpg' %}" alt="Demo image" id="field" />
<img src="{% static 'top_scroll/images/demo/gnome.jpg' %}" alt="Demo image" id="gnome" />
<img src="{% static 'top_scroll/images/demo/pencils.jpg' %}" alt="Demo image" id="pencils" />
<img src="{% static 'top_scroll/images/demo/golf.jpg' %}" alt="Demo image" id="golf" />

上面几乎是图像 html 文件中的所有代码,有人知道为什么我总是收到无效的 block 标记:“静态”错误吗?我的 base.html 的顶部有 {% load staticfiles %} 那么 django 是否需要在每个具有静态函数的文件上使用它,即使它被称为文本包含?

最佳答案

是的,您应该在每个使用 {% static %} 标签的模板中{% load staticfiles %}

摘自 documentation for the {% include %} tag :

The include tag should be considered as an implementation of “render this subtemplate and include the HTML”, not as “parse this subtemplate and include its contents as if it were part of the parent”. This means that there is no shared state between included templates – each include is a completely independent rendering process.

关于python - 为什么我会得到无效的 block 标记 : 'static' error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29178354/

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