Issue
I am getting an error while deploying app on heroku
Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail
Everything is working perfectly fine on heroku local
here are some of settings that I did
ALLOWED_HOSTS = ['0.0.0.0']
and here is Procfile
web: python manage.py runserver 0.0.0.0:$PORT
Here are my heroku logs
2022-07-10T16:25:15.788202+00:00 app[web.1]: The above exception was the direct cause of the following exception:
2022-07-10T16:25:15.788202+00:00 app[web.1]:
2022-07-10T16:25:15.788210+00:00 app[web.1]: Traceback (most recent call last):
2022-07-10T16:25:15.788218+00:00 app[web.1]: File "/app/manage.py", line 22, in <module>
2022-07-10T16:25:15.788278+00:00 app[web.1]: main()
2022-07-10T16:25:15.788285+00:00 app[web.1]: File "/app/manage.py", line 18, in main
2022-07-10T16:25:15.788341+00:00 app[web.1]: execute_from_command_line(sys.argv)
2022-07-10T16:25:15.788349+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
2022-07-10T16:25:15.788475+00:00 app[web.1]: utility.execute()
2022-07-10T16:25:15.788483+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
2022-07-10T16:25:15.788599+00:00 app[web.1]: self.fetch_command(subcommand).run_from_argv(self.argv)
2022-07-10T16:25:15.788606+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/base.py", line 414, in run_from_argv
2022-07-10T16:25:15.788717+00:00 app[web.1]: self.execute(*args, **cmd_options)
2022-07-10T16:25:15.788725+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 74, in execute
2022-07-10T16:25:15.788789+00:00 app[web.1]: super().execute(*args, **options)
2022-07-10T16:25:15.788797+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/base.py", line 460, in execute
2022-07-10T16:25:15.788909+00:00 app[web.1]: output = self.handle(*args, **options)
2022-07-10T16:25:15.788916+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 81, in handle
2022-07-10T16:25:15.788980+00:00 app[web.1]: if not settings.DEBUG and not settings.ALLOWED_HOSTS:
2022-07-10T16:25:15.788987+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 87, in __getattr__
2022-07-10T16:25:15.789055+00:00 app[web.1]: self._setup(name)
2022-07-10T16:25:15.789062+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 74, in _setup
2022-07-10T16:25:15.789135+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2022-07-10T16:25:15.789142+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 183, in __init__
2022-07-10T16:25:15.789219+00:00 app[web.1]: mod = importlib.import_module(self.SETTINGS_MODULE)
2022-07-10T16:25:15.789226+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-07-10T16:25:15.789298+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-07-10T16:25:15.789305+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-07-10T16:25:15.789371+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-07-10T16:25:15.789411+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-07-10T16:25:15.789450+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-07-10T16:25:15.789489+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-07-10T16:25:15.789535+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-07-10T16:25:15.789574+00:00 app[web.1]: File "/app/authentication/settings.py", line 98, in <module>
2022-07-10T16:25:15.789645+00:00 app[web.1]: 'NAME': env('DATABASE_NAME'),
2022-07-10T16:25:15.789652+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/environ/environ.py", line 197, in __call__
2022-07-10T16:25:15.789736+00:00 app[web.1]: return self.get_value(
2022-07-10T16:25:15.789743+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/environ/environ.py", line 407, in get_value
2022-07-10T16:25:15.789852+00:00 app[web.1]: raise ImproperlyConfigured(error_msg) from exc
2022-07-10T16:25:15.789898+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: Set the DATABASE_NAME environment variable
2022-07-10T16:25:15.946054+00:00 heroku[web.1]: Process exited with status 1
2022-07-10T16:25:16.065755+00:00 heroku[web.1]: State changed from starting to crashed
2022-07-10T16:25:16.070616+00:00 heroku[web.1]: State changed from crashed to starting
2022-07-10T16:25:20.000000+00:00 app[api]: Build succeeded
2022-07-10T16:25:20.067039+00:00 heroku[web.1]: Starting process with command `python manage.py runserver 0.0.0.0:37161`
2022-07-10T16:25:21.237371+00:00 app[web.1]: Traceback (most recent call last):
2022-07-10T16:25:21.237385+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/environ/environ.py", line 403, in get_value
2022-07-10T16:25:21.237547+00:00 app[web.1]: value = self.ENVIRON[var_name]
2022-07-10T16:25:21.237555+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/os.py", line 679, in __getitem__
2022-07-10T16:25:21.237770+00:00 app[web.1]: raise KeyError(key) from None
2022-07-10T16:25:21.237797+00:00 app[web.1]: KeyError: 'DATABASE_NAME'
2022-07-10T16:25:21.237799+00:00 app[web.1]:
2022-07-10T16:25:21.237799+00:00 app[web.1]: The above exception was the direct cause of the following exception:
2022-07-10T16:25:21.237799+00:00 app[web.1]:
2022-07-10T16:25:21.237802+00:00 app[web.1]: Traceback (most recent call last):
2022-07-10T16:25:21.237811+00:00 app[web.1]: File "/app/manage.py", line 22, in <module>
2022-07-10T16:25:21.237879+00:00 app[web.1]: main()
2022-07-10T16:25:21.237881+00:00 app[web.1]: File "/app/manage.py", line 18, in main
2022-07-10T16:25:21.237946+00:00 app[web.1]: execute_from_command_line(sys.argv)
2022-07-10T16:25:21.237953+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
2022-07-10T16:25:21.238093+00:00 app[web.1]: utility.execute()
2022-07-10T16:25:21.238101+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
2022-07-10T16:25:21.238231+00:00 app[web.1]: self.fetch_command(subcommand).run_from_argv(self.argv)
2022-07-10T16:25:21.238240+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/base.py", line 414, in run_from_argv
2022-07-10T16:25:21.238392+00:00 app[web.1]: self.execute(*args, **cmd_options)
2022-07-10T16:25:21.238408+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 74, in execute
2022-07-10T16:25:21.238490+00:00 app[web.1]: super().execute(*args, **options)
2022-07-10T16:25:21.238492+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/base.py", line 460, in execute
2022-07-10T16:25:21.238623+00:00 app[web.1]: output = self.handle(*args, **options)
2022-07-10T16:25:21.238631+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 81, in handle
2022-07-10T16:25:21.238705+00:00 app[web.1]: if not settings.DEBUG and not settings.ALLOWED_HOSTS:
2022-07-10T16:25:21.238713+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 87, in __getattr__
2022-07-10T16:25:21.238787+00:00 app[web.1]: self._setup(name)
2022-07-10T16:25:21.238795+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 74, in _setup
2022-07-10T16:25:21.238865+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2022-07-10T16:25:21.238873+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 183, in __init__
2022-07-10T16:25:21.238981+00:00 app[web.1]: mod = importlib.import_module(self.SETTINGS_MODULE)
2022-07-10T16:25:21.238983+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-07-10T16:25:21.239083+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-07-10T16:25:21.239094+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-07-10T16:25:21.239164+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-07-10T16:25:21.239210+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-07-10T16:25:21.239272+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-07-10T16:25:21.239314+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-07-10T16:25:21.239367+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-07-10T16:25:21.239438+00:00 app[web.1]: File "/app/authentication/settings.py", line 98, in <module>
2022-07-10T16:25:21.239526+00:00 app[web.1]: 'NAME': env('DATABASE_NAME'),
2022-07-10T16:25:21.239528+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/environ/environ.py", line 197, in __call__
2022-07-10T16:25:21.239624+00:00 app[web.1]: return self.get_value(
2022-07-10T16:25:21.239633+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/environ/environ.py", line 407, in get_value
2022-07-10T16:25:21.239756+00:00 app[web.1]: raise ImproperlyConfigured(error_msg) from exc
2022-07-10T16:25:21.239777+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: Set the DATABASE_NAME environment variable
2022-07-10T16:25:21.387335+00:00 heroku[web.1]: Process exited with status 1
2022-07-10T16:25:21.433687+00:00 heroku[web.1]: State changed from starting to crashed
2022-07-10T16:25:22.244946+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=noorauth.herokuapp.com request_id=955f478f-323f-4a40-8fdc-38028f4f40b8 fwd="103.184.0.73" dyno= connect= service= status=503 bytes= protocol=https
2022-07-10T16:25:22.534127+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=noorauth.herokuapp.com request_id=7f6694f9-8224-46be-b742-c20078077222 fwd="103.184.0.73" dyno= connect= service= status=503 bytes= protocol=https
2022-07-10T16:26:01.095161+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=noorauth.herokuapp.com request_id=542f9404-c45a-4264-832f-f0e4db52408c fwd="103.184.0.73" dyno= connect= service= status=503 bytes= protocol=https
2022-07-10T16:26:01.670778+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=noorauth.herokuapp.com request_id=a2e698a4-2547-4577-bc07-9b2d22293de5 fwd="103.184.0.73" dyno= connect= service= status=503 bytes= protocol=https
2022-07-10T16:29:59.391310+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=noorauth.herokuapp.com request_id=27902494-85e4-4f36-bbaa-89ae7e2895c2 fwd="103.184.0.73" dyno= connect= service= status=503 bytes= protocol=http
2022-07-10T16:30:00.717408+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=noorauth.herokuapp.com request_id=17f3bab1-2105-4677-8b94-3c2a05456c04 fwd="103.184.0.73" dyno= connect= service= status=503 bytes= protocol=http
The errors tells about the database name and everything that I have stored in .env file, what should I do, I can;t find ay help regarding the databses when deploying the app.
Solution
Your traceback is telling you that the 'DATABASE_NAME' environment variable has not been set, you can set that within your Heroku configuration.
https://devcenter.heroku.com/articles/config-vars
Another point is that your allowed hosts only has '0.0.0.0', you will need to include your Heroku app URL in there as well, or your custom URL if you are using a DNS provider.
Answered By - 0sVoid
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.