简体   繁体   English

Heroku是否在部署时按预期执行了Collectstatic?

[英]Heroku performing collectstatic as expected on deployment?

I have Django setup to collect my static files and copy them into S3 using django-storages and this works like a charm when I explicitly run 我有Django设置来收集我的静态文件,并使用django-storages将其复制到S3中,当我显式运行该文件时,它就像一个超级按钮

heroku run python manage.py collectstatic

However, I expect Heroku to perform this action automatically upon deployment (ie git push to Heroku) as described in this documentation https://devcenter.heroku.com/articles/django-assets . 但是,我希望Heroku在部署时自动执行此操作(即git push to Heroku),如本文档https://devcenter.heroku.com/articles/django-assets中所述 Apparently, the output of: 显然,输出为:

python manage.py collectstatic --dry-run --noinput

determines whether or not collectstatic is configured correctly (collectstatic works correctly when I run it explicitly). 确定collectstatic是否正确配置(当我明确运行collectstatic时,collectstatic可以正常工作)。 I get: 我得到:

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

That looks good to me but the documentation does not specify what I should see. 这对我来说看起来不错 ,但文档未指定我应该看到的内容。 When I deploy the project, everything appears to work fine and complete successfully. 当我部署项目时,一切似乎都能正常工作并成功完成。

-----> Installing dependencies using Pip (1.2.1)
       Cleaning up...
-----> Collecting static files
       16 static files copied.

-----> Discovering process types
       Procfile declares types -> web

The files do not show up in my S3 bucket though. 这些文件没有显示在我的S3存储桶中。 If I then explicitly run 如果我然后明确地运行

heroku run python manage.py collectstatic

all the files show up in the S3 bucket. 所有文件都显示在S3存储桶中。 I think Heroku should be performing this action for me and I'm not sure why its not. 我认为Heroku应该为我执行此操作,但我不确定为什么不这样做。 Is this expected behavior? 这是预期的行为吗? Should I need to do it myself? 我需要自己做吗?

Odd no one has answered you yet! 奇怪的是没有人回答你! Simply add this to the beginning of your Procfile: 只需将其添加到Procfile的开头:

web: python manage.py collectstatic --noinput

This will run python manage collectstatic every time your app is deployed on Heroku. 每当您的应用程序部署在Heroku上时,它将运行python manage collectstatic。

The cleanest way is to chain it to your existing Procfile like so: 最干净的方法是将其链接到现有的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

Credit goes to Matthew Phiong & his awesome blog post 感谢Matthew Phiong 及其出色的博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM