. Advertisement .
..3..
. Advertisement .
..4..
I’m trying to run a new project. I do a couple of things like this:
(cb)clime@den /srv/www/cb/cb/settings $ ll
total 24
-rw-rw-r--. 1 clime clime 8230 Oct 2 02:56 base.py
-rw-rw-r--. 1 clime clime 489 Oct 2 03:09 development.py
-rw-rw-r--. 1 clime clime 24 Oct 2 02:34 __init__.py
-rw-rw-r--. 1 clime clime 471 Oct 2 02:51 production.py
(cb)clime@den /srv/www/cb/cb/settings $ cat development.py
from base import *
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1', '31.31.78.149']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'cwu',
'USER': 'clime',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
MEDIA_ROOT = '/srv/www/cb/media/'
STATIC_ROOT = '/srv/www/cb/static/'
TEMPLATE_DIRS = (
'/srv/www/cb/web/templates',
'/srv/www/cb/templates',
)
(cb)clime@den /srv/www/cb $ cat manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cb.settings.development")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
django.template.loader.add_to_builtins('web.templatetags.cb_tags')
from endless_pagination.templatetags import endless
from django.conf import settings
PER_PAGE = getattr(settings, 'ENDLESS_PAGINATION_PER_PAGE', 10)
But in my program, I am getting the warning:
(cb)clime@den /srv/www/cb $ ./manage.py runserver
ImproperlyConfigured: The SECRET_KEY setting must not be empty.
Can someone explain why the “django.core.exceptions.improperlyconfigured: the secret_key setting must not be empty” issue happened? Where have I gone wrong? Thank you!
The cause:
I think this error appeared due to a stale compiled binary (.pyc) file. After all such files were deleted in my project, the server runned again.
Solution:
If you come across this error, the best solution is don’t make any changes seemingly-related to django-settings.
After reorganizing the settings according to Daniel Greenfield’s book Two scoops Django, I encountered the same problem.
I solved the problem by setting
In
manage.py
orwsgi.py
.Update:
The
local
filename (settings/local.py), which is located in my settings folder and contains the settings for my local environment, is used in the solution above.You can also resolve the issue by keeping all your settings in settings/base.py, and then creating 3 separate settings files to support your staging, production and dev environments.
The settings folder will look something like this:
Keep the following code in your
settings/__init__.py