V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
maxint64
V2EX  ›  Django

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

  •  
  •   maxint64 · 2013-04-21 01:23:26 +08:00 · 4950 次点击
    这是一个创建于 4020 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我有两个模板,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(或其他的静态文件)?
    6 条回复    1970-01-01 08:00:00 +08:00
    maxint64
        1
    maxint64  
    OP
       2013-04-21 01:30:39 +08:00
    补充:django版本为1.5.1
    imzoke
        2
    imzoke  
       2013-04-21 01:34:02 +08:00
    使用前需要先 load 。
    {% load staticfiles %}
    maxint64
        3
    maxint64  
    OP
       2013-04-21 01:36:20 +08:00
    @imzoke base.html里有{% load staticfiles %},index.html里也还要写?
    imzoke
        4
    imzoke  
       2013-04-21 01:38:16 +08:00   ❤️ 1
    @maxint64 对的,每个要用到的模版页面都要 load 才能使用的。
    zyAndroid
        5
    zyAndroid  
       2013-04-21 01:45:16 +08:00
    @maxint64 LS正解
    maxint64
        6
    maxint64  
    OP
       2013-04-21 01:48:38 +08:00
    @imzoke 原来如此
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5335 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 07:06 · PVG 15:06 · LAX 00:06 · JFK 03:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.