Py学习  »  Django

STATICFILES_DIRS配置问题

自学py的大二学生 • 6 年前 • 1957 次点击  
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static/"),
]

我这样配置了static文件,html里{% load static %}后面的{% static 'css/style.css' %}都没有问题,可就是css样式加载不出来,terminal给我报了一个错误:

"The STATICFILES_DIRS setting should "
ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
[21/May/2017 11:18:43] "GET /static/images/logo.png HTTP/1.1" 500 59
[21/May/2017 11:18:43] "GET /static/css/station_list.css HTTP/1.1" 500 59

怎么才能让css显示出来,dirs该怎么配才对,Django版本:1.11

最后一次修改于 (2017-05-22 09:45)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/2018
 
1957 次点击  
文章 [ 4 ]  |  最新文章 6 年前
自学py的大二学生
Reply   •   1 楼
自学py的大二学生    6 年前

@Py站长 debug是true,有一次直接访问css文件他显示了一句访问时一个问题出现,请联系管理员

Py站长
Reply   •   2 楼
Py站长    6 年前

@自学py的大二学生 你是在debug,还是非debug?

非debug的话,需要执行 python manage.py collectstatic

http://stackoverflow.com/questions/34586114/whats-the-point-of-djangos-collectstatic

自学py的大二学生
Reply   •   3 楼
自学py的大二学生    6 年前

@Py站长 我也放空以后,不报错了,但是css样式和图片还是没有显示出来,终端这样显示:

[22/May/2017 01:40:58] "GET /raise/station/ HTTP/1.1" 200 2940
[22/May/2017 01:40:58] "GET /static/img/logo.png HTTP/1.1" 404 1649
[22/May/2017 01:40:58] "GET /static/css/station_list.css HTTP/1.1" 404 1673

看起来路径找对了但是是404,文件名什么的也都没问题,为什么还是没加载出来css

Py站长
Reply   •   4 楼
Py站长    6 年前

你最好把django的版本写出来下

另外,ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting

是指 STATICFILES_DIRS 和 STATIC_ROOT 不要有关联。像我的配置是放空

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)