2013-07-18 197 views
7

我試圖用heroku部署我現有的django項目,遵循heroku提供的步驟,並根據需要進行調整以適合我的項目。只是爲了通過什麼我迄今所做的快速運行:用Heroku部署Django

  • 安裝Django的工具區在我的virtualenv
  • 在我的項目的命名Procile根,其中包括創造了一個Procfile:

    web: gunicorn projectname.wsgi 
    
  • 使用foreman start確認我的項目仍在本地正常運行

  • 創建requirements.txt使用pip freeze並把它放在我的項目
  • 根添加以下到settings.py

    import dj_database_url 
    DATABASES['default'] = dj_database_url.config() 
    
    # Honor the 'X-Forwarded-Proto' header for request.is_secure() 
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 
    
    # Allow all host headers 
    ALLOWED_HOSTS = ['*'] 
    
    # Static asset configuration 
    import os 
    BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 
    STATIC_ROOT = 'staticfiles' 
    STATIC_URL = '/static/' 
    
    STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'), 
    ) 
    

這是一個地步,我有點糊塗,演練沒有提及發生了什麼與我現有的數據庫設置,保持原樣,刪除,更改?

  • 添加以下到wsgi.py:

    from django.core.wsgi import get_wsgi_application 
    from dj_static import Cling 
    
    application = Cling(get_wsgi_application()) 
    
  • 添加的Heroku作爲遠程Git推我的項目的Heroku。有效。

  • heroku ps:scale web=1

然而,當我嘗試訪問我的項目,我得到一個Application Error。當我檢查與英雄heroku ps --app projectname狀態它說,測功機已經崩潰。重新啓動什麼也不做。

heroku logs --app projectname產量:

2013-07-18T00:01:14.246956+00:00 heroku[web.1]: Starting process with command `gunicorn projectname.wsgi` 
2013-07-18T00:01:16.054952+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Starting gunicorn 17.5 
2013-07-18T00:01:16.058972+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Listening at: http://0.0.0.0:55131 (2) 
2013-07-18T00:01:16.061566+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Using worker: sync 
2013-07-18T00:01:16.080073+00:00 app[web.1]: 2013-07-18 00:01:16 [7] [INFO] Booting worker with pid: 7 
2013-07-18T00:01:16.091347+00:00 app[web.1]: Traceback (most recent call last): 
2013-07-18T00:01:16.091347+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in spawn_worker 
2013-07-18T00:01:16.091347+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process 
2013-07-18T00:01:16.091347+00:00 app[web.1]:  worker.init_process() 
2013-07-18T00:01:16.091347+00:00 app[web.1]:  self.wsgi = self.app.wsgi() 
2013-07-18T00:01:16.091347+00:00 app[web.1]:  self.callable = self.load() 
2013-07-18T00:01:16.091558+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 353, in import_app 
2013-07-18T00:01:16.091347+00:00 app[web.1]:  return util.import_app(self.app_uri) 
2013-07-18T00:01:16.091558+00:00 app[web.1]:  __import__(module) 
2013-07-18T00:01:16.091347+00:00 app[web.1]: 2013-07-18 00:01:16 [7] [ERROR] Exception in worker process: 
2013-07-18T00:01:16.091347+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 33, in load 
2013-07-18T00:01:16.091558+00:00 app[web.1]: Traceback (most recent call last): 
2013-07-18T00:01:16.091771+00:00 app[web.1]:  return util.import_app(self.app_uri) 
2013-07-18T00:01:16.091771+00:00 app[web.1]:  __import__(module) 
2013-07-18T00:01:16.091558+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process 
2013-07-18T00:01:16.091558+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 115, in wsgi 
2013-07-18T00:01:16.091771+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 33, in load 
2013-07-18T00:01:16.091347+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 115, in wsgi 
2013-07-18T00:01:16.091558+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in spawn_worker 
2013-07-18T00:01:16.091558+00:00 app[web.1]:  self.callable = self.load() 
2013-07-18T00:01:16.091771+00:00 app[web.1]: ImportError: No module named projectname.wsgi 
2013-07-18T00:01:16.091558+00:00 app[web.1]: ImportError: No module named projectname.wsgi 
2013-07-18T00:01:16.091558+00:00 app[web.1]:  self.wsgi = self.app.wsgi() 
2013-07-18T00:01:16.091558+00:00 app[web.1]:  worker.init_process() 
2013-07-18T00:01:16.099257+00:00 app[web.1]: 2013-07-18 00:01:16 [7] [INFO] Worker exiting (pid: 7) 
2013-07-18T00:01:16.091771+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 353, in import_app 
2013-07-18T00:01:16.286985+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Shutting down: Master 
2013-07-18T00:01:16.288144+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Reason: Worker failed to boot. 
2013-07-18T00:01:17.956769+00:00 heroku[web.1]: Process exited with status 3 
2013-07-18T00:01:17.981029+00:00 heroku[web.1]: State changed from starting to crashed 
2013-07-18T00:11:46.404151+00:00 heroku[web.1]: State changed from crashed to starting 
2013-07-18T00:11:50.427658+00:00 heroku[web.1]: Starting process with command `gunicorn projectname.wsgi` 
2013-07-18T00:11:51.405718+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Starting gunicorn 17.5 
2013-07-18T00:11:51.406995+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Listening at: http://0.0.0.0:21344 (2) 
2013-07-18T00:11:51.407226+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Using worker: sync 
2013-07-18T00:11:51.418300+00:00 app[web.1]: 2013-07-18 00:11:51 [7] [INFO] Booting worker with pid: 7 
2013-07-18T00:11:51.425145+00:00 app[web.1]: Traceback (most recent call last): 
2013-07-18T00:11:51.425145+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 33, in load 
2013-07-18T00:11:51.425145+00:00 app[web.1]: 2013-07-18 00:11:51 [7] [ERROR] Exception in worker process: 
2013-07-18T00:11:51.425145+00:00 app[web.1]:  self.callable = self.load() 
2013-07-18T00:11:51.425145+00:00 app[web.1]:  worker.init_process() 
2013-07-18T00:11:51.425145+00:00 app[web.1]:  self.wsgi = self.app.wsgi() 
2013-07-18T00:11:51.425145+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 115, in wsgi 
2013-07-18T00:11:51.425145+00:00 app[web.1]:  return util.import_app(self.app_uri) 
2013-07-18T00:11:51.425145+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in spawn_worker 
2013-07-18T00:11:51.425145+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process 
2013-07-18T00:11:51.425341+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 353, in import_app 
2013-07-18T00:11:51.425341+00:00 app[web.1]:  __import__(module) 
2013-07-18T00:11:51.425341+00:00 app[web.1]: ImportError: No module named projectname.wsgi 
2013-07-18T00:11:51.425341+00:00 app[web.1]: Traceback (most recent call last): 
2013-07-18T00:11:51.425341+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in spawn_worker 
2013-07-18T00:11:51.425341+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process 
2013-07-18T00:11:51.425341+00:00 app[web.1]:  self.callable = self.load() 
2013-07-18T00:11:51.425341+00:00 app[web.1]:  worker.init_process() 
2013-07-18T00:11:51.425341+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 115, in wsgi 
2013-07-18T00:11:51.425341+00:00 app[web.1]:  self.wsgi = self.app.wsgi() 
2013-07-18T00:11:51.425513+00:00 app[web.1]:  return util.import_app(self.app_uri) 
2013-07-18T00:11:51.425513+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 33, in load 
2013-07-18T00:11:51.425513+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 353, in import_app 
2013-07-18T00:11:51.425513+00:00 app[web.1]:  __import__(module) 
2013-07-18T00:11:51.425513+00:00 app[web.1]: ImportError: No module named projectname.wsgi 
2013-07-18T00:11:51.425868+00:00 app[web.1]: 2013-07-18 00:11:51 [7] [INFO] Worker exiting (pid: 7) 
2013-07-18T00:11:51.550395+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Shutting down: Master 
2013-07-18T00:11:51.550395+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Reason: Worker failed to boot. 
2013-07-18T00:11:52.851413+00:00 heroku[web.1]: Process exited with status 3 
2013-07-18T00:11:52.867339+00:00 heroku[web.1]: State changed from starting to crashed 
2013-07-18T00:14:14.285978+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=projectname.herokuapp.com fwd="173.54.54.86" dyno= connect= service= status=503 bytes= 
2013-07-18T00:14:14.405875+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=projectname.herokuapp.com fwd="173.54.54.86" dyno= connect= service= status=503 bytes= 

任何幫助/建議將不勝感激,我發現沒有辦法直接的Heroku在此聯繫,這裏的一切是指你左右。

回答

0

那麼不太確定。儘管heroku的文檔建議您嘗試過。我真的不確定gunicorn在heroku中的安裝位置,以及它如何導入django項目。在過程中更容易的方式/ Django的設置服務器似乎是

網站:斌/ gunicorn_django --workers = 4 --bind = 0.0.0.0:$ PORT django_project/settings.py

推薦在這裏: http://blog.abhiomkar.in/2011/09/17/deploying-django-on-heroku-mac-os-x/

+0

謝謝,但是,並沒有詳細說明我的數據庫設置會發生什麼。 – apardes

+0

那麼你可以使用這樣的事情ATABASES = {'default':dj_database_url.config(default ='postgres:// settings_stuff')}。你也應該檢查https://devcenter.heroku.com/articles/heroku-postgresql#connection-in-python以瞭解連接到數據庫 – dusual

2

這一個地步,我有點糊塗了,演練再沒提 什麼我現有數據庫的設置情況,保留原樣, 刪除,更改?

我也跟着他們的漫遊,並有同樣的問題。對我來說,這是DATABASES聲明造成的錯誤。我用他們提供的數據庫配置替換了我的數據庫配置,但只能將其添加到已由數據庫設置創建的字典中。因此,不要替換您的數據庫語句,只需添加:

DATABASES['default'] = dj_database_url.config() 
2

Heroku有可能在構建過程中識別了錯誤的應用程序類型。這發生在我身上:

(venv)josephs-mbp:myproject josephfusaro$ git push heroku master 
Fetching repository, done. 
Counting objects: 27, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (13/13), done. 
Writing objects: 100% (14/14), 1.26 KiB | 0 bytes/s, done. 
Total 14 (delta 9), reused 0 (delta 0) 

-----> Node.js app detected 

這對我跳了出來,因爲我正在構建一個Python/Django應用程序。我遇到了this Stackoverflow thread,它解釋了它會如何發生,並說明如何覆蓋構建包。在這個例子中,我們將指定的Python buildpack但是你可以命令Heroku的使用我用buildpack不管是什麼類型的應用程序,你正在構建(click here for a full list

heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python 
0

DATABASES = { 
'default': dj_database_url.config(default='sqlite:///db.sqlite') 
} 

這種形式可以在本地和英雄使用