Djoko从Heroku收集,每次都推到S3 [英] Django collectstatic from Heroku pushes to S3 everytime

查看:250
本文介绍了Djoko从Heroku收集,每次都推到S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django存储器与S3(和S3BotoStorage)的静态文件。当我从本地机器收集时,行为是按预期的,只有修改的文件被推送到S3。这个过程需要python-dateutils 1.5来检查修改的时间。



然而,在Heroku上执行相同的操作会导致每个文件被推送,不管设置是否相同。然后我查看了Heroku本身文件的修改时间,似乎是os.stat(static_filename).st_mtime与上次推送的时间一样。


$ b $这是预期的行为吗?

解决方案

尝试设置 DISABLE_COLLECTSTATIC = 1 作为您的应用程序的环境设置 - 应该禁用它在每次推送时运行。



有关详细信息,请参阅此文章 - https: //devcenter.heroku.com/articles/django-assets

 >有时,你可能不希望Heroku代表你的收藏。 
>您可以通过启用user-env-compile来禁用collectstatic:

$ heroku实验室:enable user-env-compile
$ heroku config:set DISABLE_COLLECTSTATIC = 1

我发现只需设置配置就可以了 - 不需要也启用 user-env-编译 - 这可能是从实验室转移到生产中?



注意部署由Heroku python buildpack管理,您可以可以在这里看到 - https://github.com/heroku/heroku-buildpack-python/



编辑1



我刚完成了一堆测试并且可以确认 DISABLE_COLLECTSTATIC 确实禁用收藏,不管 user-env-compile 设置 - 我认为现在在主干(但这是猜测)。似乎不在乎设置是什么 - 如果 DISABLE_COLLECTSTATIC 作为一个config var使用它。


I'm using django-storages for static files with S3 (and S3BotoStorage). When I do collectstatic from my local machine, the behaviour is as expected, where only modified files are pushed to S3. This process needs python-dateutils 1.5 to check for modified time.

However, doing the same on Heroku results in every file being pushed regardless, although the setup is the same. I then looked into the modified time of the files on Heroku itself, and it seems like, the os.stat(static_filename).st_mtime is the same as the time of the last push.

Is this expected behaviour? Does heroku copy around files even when there is no change from git?

解决方案

Try setting DISABLE_COLLECTSTATIC=1 as an environment setting for your app - that should disable it from running on every push.

See this article for details - https://devcenter.heroku.com/articles/django-assets :

> Sometimes, you may not want Heroku to run collectstatic on your behalf.
> You can disable collectstatic by enabling user-env-compile as well:

$ heroku labs:enable user-env-compile
$ heroku config:set DISABLE_COLLECTSTATIC=1

I've found that simply setting the config will do - no need to also enable user-env-compile - it may be that that this has passed from labs into production?

NB the deployment is managed by the Heroku python buildpack, which you can see here - https://github.com/heroku/heroku-buildpack-python/

EDIT 1

I've just done a bunch of tests on this, and can confirm that DISABLE_COLLECTSTATIC does indeed disable collectstatic, irrespective of the user-env-compile setting - I think that's now in the main trunk (but that's speculation). Doesn't seem to care what the setting is - if DISABLE_COLLECTSTATIC exists as a config var it is used.

这篇关于Djoko从Heroku收集,每次都推到S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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