如何在django的模板中使用block引入CSS?

2013-04-21 01:23:26 +08:00
 maxint64
我有两个模板,base.html和index.html,index.html继承自base.html,css文件放在root/static/css目录下。
为了在index.html中引入另外一个CSS文件,我在base.html中加入了一个
{% block extracss %}{% endblock %}
然后在index.html中加入
{% block extracss %}
<link href="{% static 'css/other.css' %}" rel="stylesheet" />
{% endblock %}
但是运行的时候报错了
Invalid block tag: 'static', expected 'endblock'
看来在block之中不能出现static,请问要怎么在模板中使用block引入新的css(或其他的静态文件)?
4994 次点击
所在节点    Django
6 条回复
maxint64
2013-04-21 01:30:39 +08:00
补充:django版本为1.5.1
imzoke
2013-04-21 01:34:02 +08:00
使用前需要先 load 。
{% load staticfiles %}
maxint64
2013-04-21 01:36:20 +08:00
@imzoke base.html里有{% load staticfiles %},index.html里也还要写?
imzoke
2013-04-21 01:38:16 +08:00
@maxint64 对的,每个要用到的模版页面都要 load 才能使用的。
zyAndroid
2013-04-21 01:45:16 +08:00
@maxint64 LS正解
maxint64
2013-04-21 01:48:38 +08:00
@imzoke 原来如此

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/66468

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX