Heroku在部署时按预期执行集合



我已经设置了Django来收集我的静态文件,并使用Django -storage将它们复制到S3中,当我显式运行

时,这就像一个魅力
heroku run python manage.py collectstatic

然而,我希望Heroku在部署时自动执行此操作(即git push到Heroku),如本文档https://devcenter.heroku.com/articles/django-assets中所述。显然,

的输出
python manage.py collectstatic --dry-run --noinput

决定是否正确配置了collectstatic(当我显式运行它时,collectstatic可以正确工作)。我:

$ heroku run python manage.py collectstatic --dry-run --noinput
Running `python manage.py collectstatic --dry-run --noinput` attached to terminal... up, run.9607
Pretending to copy '/app/app_pkg/static/robots.txt'
.... # Lot of similar outputs not shown
16 static files copied.

这看起来很好对我来说,但是文档没有指定我应该看到什么。当我部署项目时,一切似乎都运行良好,并成功完成。

-----> Installing dependencies using Pip (1.2.1)
       Cleaning up...
-----> Collecting static files
       16 static files copied.
-----> Discovering process types
       Procfile declares types -> web

文件没有显示在我的S3存储桶中。如果我显式地运行

heroku run python manage.py collectstatic

所有文件都显示在S3桶中。我认为Heroku应该为我表演这个动作,我不确定为什么不是。这是预期行为吗?需要我自己做吗?

还没人回答你!只需将此添加到Procfile的开头:

web: python manage.py collectstatic --noinput

这将在每次应用部署到Heroku上时运行python manage collectstatic。

最干净的方法是将它链接到现有的Procfile中,如下所示:

web: python my_django_app/manage.py collectstatic --noinput; bin/gunicorn_django --workers=4 --bind=0.0.0.0:$PORT my_django_app/settings.py

来源:Matthew Phiong &他的博文

最新更新