首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
›
Django Project
›
Django REST Framework
V2EX
›
Django
如何在django的模板中使用block引入CSS?
maxint64
·
2013-04-21 01:23:26 +08:00
· 5256 次点击
这是一个创建于 4367 天前的主题,其中的信息可能已经有所发展或是发生改变。
我有两个模板,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(或其他的静态文件)?
HTML
block
CSS
6 条回复
•
1970-01-01 08:00:00 +08:00
1
maxint64
OP
2013-04-21 01:30:39 +08:00
补充:django版本为1.5.1
2
imzoke
2013-04-21 01:34:02 +08:00
使用前需要先 load 。
{% load staticfiles %}
3
maxint64
OP
2013-04-21 01:36:20 +08:00
@
imzoke
base.html里有{% load staticfiles %},index.html里也还要写?
4
imzoke
2013-04-21 01:38:16 +08:00
1
@
maxint64
对的,每个要用到的模版页面都要 load 才能使用的。
5
zyAndroid
2013-04-21 01:45:16 +08:00
@
maxint64
LS正解
6
maxint64
OP
2013-04-21 01:48:38 +08:00
@
imzoke
原来如此
关于
·
帮助文档
·
博客
·
API
·
FAQ
·
实用小工具
·
2381 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 22ms ·
UTC 09:37
·
PVG 17:37
·
LAX 02:37
·
JFK 05:37
Developed with
CodeLauncher
♥ Do have faith in what you're doing.