maxint64
V2EX  ›  Django

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

  •  
  •   maxint64 · Apr 21, 2013 · 6306 views
    This topic created in 4957 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
    maxint64
    OP
    Apr 21, 2013
    1
    补充:django版本为1.5.1
    imzoke
    imzoke
    Apr 21, 2013
    2
    使用前需要先 load 。
    {% load staticfiles %}
    maxint64
    maxint64
    OP
    Apr 21, 2013
    3
    @imzoke base.html里有{% load staticfiles %},index.html里也还要写?
    imzoke
    imzoke
    Apr 21, 2013❤️1
    4
    @maxint64 对的,每个要用到的模版页面都要 load 才能使用的。
    zyAndroid
    zyAndroid
    Apr 21, 2013
    5
    @maxint64 LS正解
    maxint64
    maxint64
    OP
    Apr 21, 2013
    6
    @imzoke 原来如此
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1920 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:33 · PVG 23:33 · LAX 07:33 · JFK 10:33
    ♥ Do have faith in what you're doing.