【发布时间】:2020-11-24 01:26:42
【问题描述】:
命令heroku run python manage.py collectstatic 给我返回类似的东西
163 static files copied to '/app/live-static-files/static-root',
509 post-processed.
这是我的设置:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', # White Noise
'django.contrib.sessions.middleware.SessionMiddleware',
...
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "live-static-files", "static-root")
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "live-static-files", "media-root")
DISABLE_COLLECTSTATIC = 0
通过heroku run bash 我转到/app/live-static-files/static-root 并看到它是空的(该文件夹存在,因为它在带有.gitkeep 的repo 中)并且服务器对所有请求都给出500 错误。
现在使用heroku run bash 我尝试python manage.py collectstatic 并且它有效!但是在heroku restart 之后又是空的。
为什么 Heroku 告诉它复制了 statics,甚至告诉了 statics 文件夹的正确路径但实际上并没有这样做?为什么它实际上没有这样做?
【问题讨论】:
-
你不能通过
heroku run运行collectstatic。此类命令在一次性测功机中运行,一旦命令结束就会被丢弃。确保将其作为构建过程的一部分运行 (this is the default) 或将静态资产存储在共享位置,例如在 Amazon S3 或 Azure Blob 存储上。 -
@Chris 我在配置中有
DISABLE_COLLECTSTATIC = 0,无论如何它不起作用,部署后静态文件夹为空 -
这不属于您的设置文件,它是一个 Heroku config var。用
heroku config:unset DISABLE_COLLECTSTATIC清除它。 -
@Chris 是的,我知道
标签: django heroku django-staticfiles