maxint64
V2EX  ›  Django

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

  •  
  •   maxint64 · Apr 21, 2013 · 5844 views
    This topic created in 4781 days ago, the information mentioned may be changed or developed.
    我有两个模板,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 replies    1970-01-01 08:00:00 +08:00
    maxint64
        1
    maxint64  
    OP
       Apr 21, 2013
    补充:django版本为1.5.1
    imzoke
        2
    imzoke  
       Apr 21, 2013
    使用前需要先 load 。
    {% load staticfiles %}
    maxint64
        3
    maxint64  
    OP
       Apr 21, 2013
    @imzoke base.html里有{% load staticfiles %},index.html里也还要写?
    imzoke
        4
    imzoke  
       Apr 21, 2013   ❤️ 1
    @maxint64 对的,每个要用到的模版页面都要 load 才能使用的。
    zyAndroid
        5
    zyAndroid  
       Apr 21, 2013
    @maxint64 LS正解
    maxint64
        6
    maxint64  
    OP
       Apr 21, 2013
    @imzoke 原来如此
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2938 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 07:18 · PVG 15:18 · LAX 00:18 · JFK 03:18
    ♥ Do have faith in what you're doing.