Need Help in Django Deployment

Question:

I want help in deploying my django app. i tried deploying on heroku but its giving me alot of errors.

like: SECRET_KEY must not be empty(even if its not empty)

APP_CRASHED

i’ve tried hosting on pythonanywhere too but it gives me errors as well.

also, i’m using postgres as production database.

any help would be appreciated

2019-11-12T10:52:11.710011+00:00 app[web.1]: worker.init_process()
2019-11-12T10:52:11.710014+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-11-12T10:52:11.710016+00:00 app[web.1]: self.load_wsgi()
2019-11-12T10:52:11.710018+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-11-12T10:52:11.710020+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-11-12T10:52:11.710026+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-11-12T10:52:11.710028+00:00 app[web.1]: self.callable = self.load()
2019-11-12T10:52:11.710030+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-11-12T10:52:11.710032+00:00 app[web.1]: return self.load_wsgiapp()
2019-11-12T10:52:11.710034+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-11-12T10:52:11.710036+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-11-12T10:52:11.710038+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2019-11-12T10:52:11.710040+00:00 app[web.1]: __import__(module)
2019-11-12T10:52:11.710046+00:00 app[web.1]: File "/app/djecommerce/wsgi.py", line 5, in <module>
2019-11-12T10:52:11.710048+00:00 app[web.1]: application = get_wsgi_application()
2019-11-12T10:52:11.710050+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-11-12T10:52:11.710052+00:00 app[web.1]: django.setup(set_prefix=False)
2019-11-12T10:52:11.710054+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
2019-11-12T10:52:11.710056+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2019-11-12T10:52:11.710058+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
2019-11-12T10:52:11.710060+00:00 app[web.1]: self._setup(name)
2019-11-12T10:52:11.710062+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
2019-11-12T10:52:11.710063+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2019-11-12T10:52:11.710065+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 176, in __init__
2019-11-12T10:52:11.710068+00:00 app[web.1]: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
2019-11-12T10:52:11.710114+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
2019-11-12T10:52:11.710770+00:00 app[web.1]: [2019-11-12 10:52:11 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-11-12T10:52:11.833938+00:00 app[web.1]: [2019-11-12 10:52:11 +0000] [11] [ERROR] Exception in worker process
2019-11-12T10:52:11.833943+00:00 app[web.1]: Traceback (most recent call last):
2019-11-12T10:52:11.833945+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-11-12T10:52:11.833948+00:00 app[web.1]: worker.init_process()
2019-11-12T10:52:11.833950+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-11-12T10:52:11.833952+00:00 app[web.1]: self.load_wsgi()
2019-11-12T10:52:11.833954+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-11-12T10:52:11.833956+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-11-12T10:52:11.833959+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-11-12T10:52:11.833961+00:00 app[web.1]: self.callable = self.load()
2019-11-12T10:52:11.833965+00:00 app[web.1]: return self.load_wsgiapp()
2019-11-12T10:52:11.833967+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-11-12T10:52:11.833969+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-11-12T10:52:11.833971+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2019-11-12T10:52:11.833974+00:00 app[web.1]: __import__(module)
2019-11-12T10:52:11.833976+00:00 app[web.1]: File "/app/djecommerce/wsgi.py", line 5, in <module>
2019-11-12T10:52:11.833978+00:00 app[web.1]: application = get_wsgi_application()
2019-11-12T10:52:11.833981+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-11-12T10:52:11.833983+00:00 app[web.1]: django.setup(set_prefix=False)
2019-11-12T10:52:11.833985+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
2019-11-12T10:52:11.833988+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2019-11-12T10:52:11.833990+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
2019-11-12T10:52:11.833991+00:00 app[web.1]: self._setup(name)
2019-11-12T10:52:11.833993+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
2019-11-12T10:52:11.833995+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2019-11-12T10:52:11.833997+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 176, in __init__
2019-11-12T10:52:11.833999+00:00 app[web.1]: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
2019-11-12T10:52:11.834005+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
2019-11-12T10:52:11.834714+00:00 app[web.1]: [2019-11-12 10:52:11 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-11-12T10:52:11.880751+00:00 app[web.1]: Traceback (most recent call last):
2019-11-12T10:52:11.880758+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 210, in run
2019-11-12T10:52:11.881198+00:00 app[web.1]: self.sleep()
2019-11-12T10:52:11.881203+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 360, in sleep
2019-11-12T10:52:11.881565+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
2019-11-12T10:52:11.881569+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
2019-11-12T10:52:11.881848+00:00 app[web.1]: self.reap_workers()
2019-11-12T10:52:11.881852+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2019-11-12T10:52:11.882283+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2019-11-12T10:52:11.882341+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2019-11-12T10:52:11.882344+00:00 app[web.1]:
2019-11-12T10:52:11.882346+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2019-11-12T10:52:11.882348+00:00 app[web.1]:
2019-11-12T10:52:11.882353+00:00 app[web.1]: Traceback (most recent call last):
2019-11-12T10:52:11.882357+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2019-11-12T10:52:11.882580+00:00 app[web.1]: sys.exit(run())
2019-11-12T10:52:11.882582+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
2019-11-12T10:52:11.882755+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2019-11-12T10:52:11.882759+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 223, in run
2019-11-12T10:52:11.883018+00:00 app[web.1]: super(Application, self).run()
2019-11-12T10:52:11.883022+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
2019-11-12T10:52:11.883198+00:00 app[web.1]: Arbiter(self).run()
2019-11-12T10:52:11.883202+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 232, in run
2019-11-12T10:52:11.883457+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2019-11-12T10:52:11.883461+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 345, in halt
2019-11-12T10:52:11.883815+00:00 app[web.1]: self.stop()
2019-11-12T10:52:11.883840+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
2019-11-12T10:52:11.884179+00:00 app[web.1]: time.sleep(0.1)
2019-11-12T10:52:11.884183+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
2019-11-12T10:52:11.884446+00:00 app[web.1]: self.reap_workers()
2019-11-12T10:52:11.884449+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2019-11-12T10:52:11.884881+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2019-11-12T10:52:11.884907+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2019-11-12T10:52:12.019473+00:00 heroku[web.1]: State changed from up to crashed
2019-11-12T10:52:12.004142+00:00 heroku[web.1]: Process exited with status 1
2019-11-12T10:52:22.743225+00:00 app[api]: Starting process with command `python manage.py migrate` by user [email protected]
2019-11-12T10:52:33.963000+00:00 heroku[run.2955]: State changed from starting to up
2019-11-12T10:52:33.936796+00:00 heroku[run.2955]: Awaiting client
2019-11-12T10:52:34.007350+00:00 heroku[run.2955]: Starting process with command `python manage.py migrate`
2019-11-12T10:52:46.514812+00:00 heroku[run.2955]: State changed from up to complete
2019-11-12T10:52:46.502306+00:00 heroku[run.2955]: Process exited with status 0
2019-11-12T10:53:04.809501+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=secure-basin-29081.herokuapp.com request_id=a0609543-47a1-4f49-86db-faac1762ab33 fwd="196.194.23.86" dyno= connect= service= status=503 bytes= protocol=https
2019-11-12T10:53:05.348482+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=secure-basin-29081.herokuapp.com request_id=4eed1f99-b1dc-4db9-847a-ed831f3a8108 fwd="196.194.23.86" dyno= connect= service= status=503 bytes= protocol=https

Thanks in advance.

Asked By: Hic

||

Answers:

The problem is that you share settings in 3 files, but forget to set settings module in wsgi.py file.

Try to edit this os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djecommerce.settings')
to os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djecommerce.settings.production')