简体   繁体   中英

How to set relative url for a css file in Django

在此处输入图片说明

My django project is pictured above:

I'm trying to set a path to my css using:

<link href="{% static "css/bootstrap.min.css" %} rel="stylesheet">

In my settings.py I have:

STATIC_URL = '/static/'

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR,  'templates'),

When I run the project I get:

TemplateSyntaxError at /index/

Invalid block tag: 'static'

What am I doing wrong?

The problem maybe is: You don't loaded tag for staticfiles.

{% load staticfiles %}

You should load staticfiles first, and then you can use static tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM