Django css file is not working

html css django

42 观看

1回复

154 作者的声誉

I'm new in Django and get problem. I have:

STATIC_URL = '/static/'
STATIC_ROOT = '/static/'

at my settings.py, have Project/mainapp/static folder and css/header.css inside that folder. Also i have

{% load staticfiles %}
<link rel="stylesheet" href="{% static 'css/header.css' %}" type="text/css">

at my header html. Browser tries localhost/static/css/header.css but find nothing there. What am i doing wrong? Thanks!

作者: D. Make 的来源 发布者: 2017 年 12 月 27 日

回应 1


1

2995 作者的声誉

决定

Define STATICFILES_DIRS in your settings as below:

STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'), )

BASE_DIR is global variable you can find in same settings.py which points to project's working directory. static is your folder inside root directory of your app.

And load static in template instead of staticfiles like below:

{% load static %}
作者: Gahan 发布者: 2017 年 12 月 27 日
32x32