【发布时间】:2020-05-18 18:08:16
【问题描述】:
我有一个 django 项目,突然(更新 PyCharm 后)静态文件无法再加载。这是项目结构:
├── _quanttool
│ ├── _quanttool
│ │ ├── __init__.py
│ │ ├── asgi.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── _static
│ │ ├── css
│ │ ├── img
│ │ ├── js
│ │ ├── scss
│ │ └── vendor
│ ├── _templates
│ │ ├── base
│ │ ├── funds_tool
│ │ └── transaction_list
│ ├── funds_tool
.
.
.
│ ├── db.sqlite3
│ └── manage.py
├── venv
├── .gitignore
└── README.md
在我配置的settings.py文件中:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/_static/'
STATIC_ROOT = '_static'
STATICFILES_LOCATION = [os.path.join(BASE_DIR, '_static')]
在基本 HTML 模板中,我设置了 {% load static %} 和 <link href="{% static 'css/sb-admin-2.min.css' %}" rel="stylesheet">
我真的不明白为什么我突然收到错误: "GET /_static/css/sb-admin-2.css HTTP/1.1" 404 1682" ...
知道为什么 Django 找不到静态文件了吗?
最好的
【问题讨论】:
-
你有没有DEBUG=False
-
不,它设置为 True,
'django.contrib.staticfiles'也包含在INSTALLED_APPS中。
标签: python django django-staticfiles