Django load block for css

2019-03-14 05:32发布

I have a few pages. For every page I need load unique css. For all static files I use this. In the head of index.html I have:

{% block css  %}

{% endblock %}

But, for example, in contact.html I use:

{% extends "index.html" %}    
{% block css %}
    <link rel="stylesheet" href="{% static "css/contact.css" %}" type="text/css" />
    {% endblock %}

And its print error: Invalid block tag: 'static', expected 'endblock'. How to fix it?

3条回答
欢心
2楼-- · 2019-03-14 06:06

You need to use {% load static %} first.

查看更多
甜甜的少女心
3楼-- · 2019-03-14 06:11

Your code needs to be refined.

You are using double quotes, where you need to use an apostrophe.

Use

href ="{% static 'css/contact.css' %} "

Instead of

href ="{% static" css/contact.css" %} "
查看更多
对你真心纯属浪费
4楼-- · 2019-03-14 06:22

it is

{% block css %}

{% endblock %}
查看更多
登录 后发表回答