为什么我会收到无效的块标记:“静态”错误? - python

这是我的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文件上的所有代码,任何人都知道为什么我不断收到Invalid block标签:“静态”错误?我的base.html顶部具有{%load staticfiles%},所以django是否在每个具有静态功能的文件上都要求它,即使它被称为文本包含?

python大神给出的解决方案

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

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

include标签应被视为“呈现此子模板并包含HTML”的实现,而不应被视为“解析此子模板并像其父对象一样包含其内容”。这意味着在包含的模板之间没有共享状态–每个包含都是一个完全独立的渲染过程。