【发布时间】:2021-04-05 16:54:38
【问题描述】:
问题是来自 Django 应用程序的静态文件未在 pythonanywhere 中收集。 命令后
python manage.py collectstatic
目录中
/home/user/user.pythonanywhere.com/static
仅显示 admin 文件夹。 设置.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp'
]
css文件位置:
+---myapp
| +---static
| | \---myapp
| | \---css
| | \---myapp.css
当我在本地命令行中运行命令 python manage.py collectstatic 时,会收集来自应用程序的静态文件,问题出在 pythonanywhere。
所有动作都是标准的,我都严格按照指南做的,我不明白这是怎么回事。非常感谢
我已经阅读了有关 pythonanywhere 的所有文章以及我在 stackoverflow 和文档中找到的所有内容,但没有任何帮助解决问题。
https://help.pythonanywhere.com/pages/DjangoStaticFiles
https://help.pythonanywhere.com/pages/DebuggingStaticFiles/
https://help.pythonanywhere.com/pages/StaticFiles
更新: BASE_DIR = Path(文件).resolve().parent.parent
Bash 控制台文本输出:
You have requested to collect static files at the destination location as specified in your settings: /home/user/user.pythonanywhere.com/static This will overwrite existing files! Are you sure you want to do this? Type 'yes' to continue, or 'no' to cancel: yes 0 static files copied to '/home/user/user.pythonanywhere.com/static', 132 unmodified.
collectstatic命令后/home/user/user.pythonanywhere.com/static目录的内容:
+---admin
| +---css
| +---fonts
| +---img
| +---js
【问题讨论】:
-
BASE_DIR的值是什么?collectstatic不会生成任何关于发生的事情的文本输出吗? -
BASE_DIR = Path(file).resolve().parent.parent 您已请求在设置中指定的目标位置收集静态文件:/home/user /user.pythonanywhere.com/static 这将覆盖现有文件!你确定要这么做吗?键入“yes”继续,或“no”取消:yes 0 静态文件复制到“/home/user/user.pythonanywhere.com/static”,132 未修改。 132个静态文件它是管理静态文件。在我的本地服务器上,他收集了 133 个静态文件和一个包含我需要的 css 文件的附加文件夹
-
请更新您的问题并提供更多详细信息,请勿发表评论。看看这个答案stackoverflow.com/questions/66437690/…
-
我看到您对 css 文件位置(我相信它取自 PythonAnywhere 帮助页面?)和运行
collectstatic管理命令的位置使用了不同的结构。为了避免混淆:你能检查一下/home/user/user.pythonanywhere.com/static目录的内容吗? -
我想主要问题是我在 .gitignore 文件中添加了 /static 行?这就是为什么 pythonanywhere bash 控制台看不到静态文件的原因吗?因为他们没有在github上下载?比上传静态文件的过程是什么?你能解释一下吗?我也阅读了这篇文章,但仍然不明白:docs/3.1/ref/contrib/staticfiles/docs/3.1/howto/static-files/deployment/ @ivan-starostin 我已经阅读了你的答案。 STATIC_URL - 好的,STATIC_ROOT - 好的。我不需要 STATICFILES_DIRS,因为默认的 STATICFILES_FINDERS 设置会找到 app 的静态子目录。
标签: python django pythonanywhere django-staticfiles