2013-01-10 70 views
1

我有Django的設置,以收集我的靜態文件和使用Django,儲存它們複製到S3,這就像一個魅力時,我明確地運行Heroku在部署時按預期執行collectstatic?

heroku run python manage.py collectstatic 

不過,我希望Heroku的,一旦張開,自動執行此操作(即git推到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應該爲我執行這個動作,但我不確定它爲什麼不行。這是預期的行爲?我需要自己做嗎?

+1

在[類似線程一些詳細信息(HTTP://計算器的.com /問題/ 14417322/Django的collectstatic從 - Heroku的-推到S3-每次)。我還沒有找到解決方案。 – Jeff

+1

$ heroku實驗室:啓用用戶-env-compile –

回答

5

奇怪的還沒有人回答你呢!只需添加到您的Procfile的開頭:

web: python manage.py collectstatic --noinput 

這將運行python管理好每一個你的應用程序部署在Heroku時間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 

幸得馬修Phiong & his awesome blog post

+0

修改Procfile的確運行良好,仍然如此。謝謝。我現在使用[user-env-compile lab](https://devcenter.heroku.com/articles/django-assets#config-vars-during-build)構建Heroku(由Kenneth提及)以支持包括環境變量build(django-storage需要),以便Heroku執行靜態資產收集,而不需要修改Procfile。 – dghubble