Heroku doesn't collect static on Django but tell that it does

拈花ヽ惹草 提交于 2020-08-10 19:15:54

问题


Command heroku run python manage.py collectstatic returns me something like

163 static files copied to '/app/live-static-files/static-root', 
509 post-processed.

Here are my settings:

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

Through heroku run bash i go /app/live-static-files/static-root and see it's empty (the folder exists as it's in repo with .gitkeep) and server gives 500 error on all requests.

Now with heroku run bash i try python manage.py collectstatic and it works! But after heroku restart it's empty again.

Why Heroku tell that it copied statics, even tell the right path of the statics folder but in fact doesn't do that? Why it actually doesn't do that?


回答1:


The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy. This is similar to how many container based systems, such as Docker, operate.

In addition, under normal operations dynos will restart every day in a process known as "Cycling".

Take a read of these articles:

https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted

https://devcenter.heroku.com/articles/django-assets



来源:https://stackoverflow.com/questions/63238587/heroku-doesnt-collect-static-on-django-but-tell-that-it-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!