Django Deployment With Heroku

django, heroku

Solution

This is one point where I'm a bit confused, the walkthrough made no mention of what happens with my existing db settings, leave as is, remove, change?

I too followed their walkthrough and had the same problems. For me it was the DATABASES statement that made the error. I replaced my database configuration with the one they provide, while it must just be added to the dictionary already created by your database settings. So instead of replacing your database statement just add:

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

Problem

I'm trying to deploy my existing django project with heroku, following the walk through provided by heroku and adapting as needed to be specific to my project. Just to run quickly through what I've done so far: - installed django-toolbelt in my virtualenv created a Procfile in the root of my project named `Procile` which includes: ``` web: gunicorn projectname.wsgi ``` using `foreman start` confirmed that my project still ran properly locally - created `requirements.txt` using `pip freeze` and placed it in the root of my project added the following to `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'), ) ``` This is one point where I'm a bit confused, the walkthrough made no mention of what happens with my existing db settings, leave as is, remove, change? Added the following to wsgi.py: ``` from django.core.wsgi import get_wsgi_application from dj_static import Cling application = Cling(get_wsgi_application()) ``` added heroku as a git remote and pushed my project to heroku. It worked. - `heroku ps:scale web=1` However, when I try to access my project I get an `Application Error`. When I check the status with heroku `heroku ps --app projectname` it says the dyno has crashed. Restarting does nothing. `heroku logs --app projectname` yields: ``` 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= ``` Any help/advice would be greatly appreciated, I found no way to contact heroku directly on this, everything refers you here to so.

Original source

Related problems