为什么我会收到无效的块标记:'static' 错误?

why would I be getting Invalid block tag: 'static' error?

这是我的头像 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" %} 将它们添加到 base.

例如。 <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 文件中的所有代码,有人知道为什么我总是收到无效的块标记:'static' 错误吗?我的 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.