Reputation: 1324
I am trying to deploy my Django app on Heroku. Whenever I go to my app I am getting an error:
2020-09-06T20:31:59.000436+00:00 app[web.1]: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
2020-09-06T20:31:59.000477+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty
I have now two settings file so in my projects folder which contains the wsgi.py
. I have a folder called settings/
which is:
settings
--common.py
--development.py
--productions.py
In my production.py
I have:
from register.settings.common import *
import os
import django_heroku
DEBUG = False
ALLOWED_HOSTS = ['0.0.0.0', 'localhost', '127.0.0.1','appname.heroku.com']
SECRET_KEY = os.environ.get('SECRET_KEY')
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
django_heroku.settings(locals())
And in my wsgi.py
and manage.py
I have:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'register.settings.production')
Now I have added the Postgres add-on from the dashboard and can check that I also have it using the Heroku CLI.
I have also added a custom domain name of www.myapp.com
as well which I do not know if this is causing the issue.
For pushing to master I did:
heroku config:set DISABLE_COLLECTSTATIC=1
and then:
git push heroku master
What is causing this issue? When I do python manage.py run server
I also get the error:
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
I also get this error in my Heroku logs when I check it how can I set the secret key?
EDIT 2
The issue seems to be with my celery.py
file, however, I have tried changing the settings to point to production.py
(register in my projects root folder):
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
import django
app = Celery('register')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(settings.INSTALLED_APPS)
in my manage.py
I have:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'register.settings.development')
Which the command manage.py runserver
works however, now I get an error:
8:52:21 PM web.1 | raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
8:52:21 PM web.1 | django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
in this line in my wsgi.py file:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'register.settings.production')
application = get_wsgi_application()
Upvotes: 0
Views: 191
Reputation: 136918
It looks like you simply haven't set your SECRET_KEY
.
You try to import it from the environment in your settings
module, but this depends on an environment variable called SECRET_KEY
existing:
SECRET_KEY = os.environ.get('SECRET_KEY')
On Heroku, the best way to set this environment varialbe is to set a config var. This can be done with the Heroku CLI:
heroku config:set SECRET_KEY=some_value
or in the web dashboard.
Upvotes: 1