Django无法找到我的静态文件

时间:2017-05-21 09:12:04

标签: python django

我部署静态设置,如下所示:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static/"),
]

我在root中有一个带有一些css文件的静态文件夹,我使用的链接如下:

<link rel="stylesheet" type="text/css" href="{{STATIC_URL}}css/station_list.css'">
<img src="{{ STATIC_URL }}images/logo.png">

css路径是正确的,但html无法显示css样式,我检查终端,它说:

Not Found: /raise/station/css/station_list.css'
Not Found: /raise/station/images/logo.png

为什么路径不是/ static /而是app root?感谢。

1 个答案:

答案 0 :(得分:1)

在href属性中调用css或图像{% static 'css/style.css' %}等静态文件,{% load static %}将其置于模板顶部

相关问题