简体   繁体   English

Django突然无法加载static文件了

[英]Django suddenly can't load static files anymore

I have a django project for which suddenly (after updating PyCharm) the staticfiles can't be loaded anymore.我有一个 django 项目,突然(更新 PyCharm 之后)无法再加载静态文件。 This is the project structure:这是项目结构:

├── _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

In the settings.py file i have configured:在我配置的 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')]

In the base HTML Template I have set {% load static %} and <link href="{% static 'css/sb-admin-2.min.css' %}" rel="stylesheet">在基础 HTML 模板中,我设置了{% load static %}<link href="{% static 'css/sb-admin-2.min.css' %}" rel="stylesheet">

I really don't understand why I suddenly get the errors: "GET /_static/css/sb-admin-2.css HTTP/1.1" 404 1682"...我真的不明白为什么我突然得到错误:“GET /_static/css/sb-admin-2.css HTTP/1.1” 404 1682”...

Any idea why Django can't find the staticfiles anymore?知道为什么 Django 再也找不到静态文件了吗?

Best最好

comment out STATIC_ROOT = '_static' and add the below code to your settings.py file.注释掉STATIC_ROOT = '_static'并将以下代码添加到您的 settings.py 文件中。

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/_static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, '_static'),)

If still not work then run this command on terminal如果仍然不起作用,请在终端上运行此命令

$ python manage.py collectstatic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM