use*_*832 2 python django django-templates
这是我的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>`
Run Code Online (Sandbox Code Playgroud)
这部分是正文,上面的静态文件正确加载,我在身体中有一些我想加载的图像,它们位于同一个文件夹中,但我已将代码写入另一个文件并用于{% 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文件中的所有代码,任何人都知道为什么我一直得到无效块标记:'静态'错误?我的base.html的顶部有{%load staticfiles%}所以django在每个具有静态函数的文件上都需要它,即使它被称为文本包含?
是的,您应该{% load staticfiles %}在每个使用该{% static %}标签的模板中.
摘录自标签的文档{% include %}:
include标记应该被视为"渲染此子模板并包含HTML"的实现,而不是"解析此子模板并将其内容包含在内,就好像它是父类的一部分".这意味着包含的模板之间没有共享状态 - 每个包含都是完全独立的渲染过程.
| 归档时间: |
|
| 查看次数: |
1849 次 |
| 最近记录: |