Heroku不会在Django上收集静态信息,但会告诉它 [英] Heroku doesn't collect static on Django but tell that it does

查看:91
本文介绍了Heroku不会在Django上收集静态信息,但会告诉它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令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一起在回购中),服务器对所有请求给出500错误.

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.

现在使用heroku run bash,我尝试使用python manage.py collectstatic,它可以正常工作!但是heroku restart之后,它又是空的.

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

为什么Heroku告诉它复制了静态数据,甚至告诉了statics文件夹的正确路径,但实际上却不这样做呢?为什么它实际上不这样做?

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?

推荐答案

Heroku文件系统是短暂的-这意味着在dyno运行时,对文件系统的任何更改只会持续到dyno关闭或重新启动为止.每个dyno都会使用最新部署中的文件系统的干净副本进行引导.这类似于运行诸如Docker之类的基于容器的系统的数量.

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".

阅读这些文章:

https://help.heroku.com /K1PPS2WM/为什么我的文件上传缺失删除了

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

这篇关于Heroku不会在Django上收集静态信息,但会告诉它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆