Django load block for css

2019-03-14 05:57发布

问题:

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?

回答1:

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



回答2:

it is

{% block css %}

{% endblock %}


回答3:

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" %} "