Django 创建了 staticfiles 文件夹而不是 static 文件夹
我不知道为什么 Django 创建了一个名为 staticfiles 的文件夹,而不是预期的 static 。这可能是我在运行 python manage.pycollectstatic
后出现错误的原因:
The system cannot find the path specified: 'D:...\\static'
我的设置文件包括:
from pathlib import Path
import os
import django_heroku
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
我已经尝试将 STATIC_ROOT 中的“staticfiles”更改为“static”,但没有成功。
谁能解释一下为什么以及如何创建一个名为“static”的文件夹?
预先非常感谢您!
I do not know why Django created a folder named staticfiles rather than static as expected. That might be the reason why I got an error after running python manage.py collectstatic
:
The system cannot find the path specified: 'D:...\\static'
My settings file included:
from pathlib import Path
import os
import django_heroku
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
I had already tried to change 'staticfiles' to 'static' in STATIC_ROOT, but no success.
Could anyone please explain why and how to create a folder name "static"?
Thank you very much in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的静态文件放置在您的应用程序中
尝试删除
STATICFILES_DIRS
,以便设置为:...并尝试重新运行
python管理.pycollectstatic
collectstatic
的工作原理:STATICFILES_DIRS
收集静态文件(如果有),如果设置中没有STATICFILES_DIRS
,它会从每个应用收集静态文件STATIC_ROOT
中,因此,如果您的静态文件放置在应用内,最好删除STATICFILES_DIRS
如果仍然存在错误,请分享您的项目结构
I considered your static files are placed inside your app(s)
Try removing
STATICFILES_DIRS
so the setting will be:...and try to re-run
python manage.py collectstatic
collectstatic
works:STATICFILES_DIRS
if any, if there is noSTATICFILES_DIRS
in settings it collects static files from each appSTATIC_ROOT
, so if your static files are placed inside your app(s) better to removeSTATICFILES_DIRS
If still there is an error share your project structure