【发布时间】:2017-04-08 02:08:26
【问题描述】:
我正在学习如何使用 django,但在使用静态文件时遇到了困难。
文件(BASE_DIR 是 website,应用程序是 player):
Website
└─── player
└─── static
└─── style.css
└─── admin
在设置中:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'player/static')
在index.html:
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{ static 'style.css' %}" >
在style.css:
body {
background-color: blue
}
我跑过collectstatic。
加载后,显示的 HTML 没有 css。
控制台显示:
[23/Nov/2016 23:33:13] "GET / HTTP/1.1" 200 278
Not Found: /{ static 'style.css' %}
[23/Nov/2016 23:33:13] "GET /%7B%20static%20'style.css'%20%%7D HTTP/1.1" 404 2172
【问题讨论】:
-
您是否尝试进行设置:1)
STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), )2)STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')3)STATIC_URL = '/static/' -
@Hybrid 是的,即使使用这些设置,它仍然找不到文件。
-
检查模板指令中的拼写是否存在基本错误
标签: django django-templates django-staticfiles