Skip to content

Instantly share code, notes, and snippets.

@nivir
Last active December 6, 2016 21:28
Show Gist options
  • Save nivir/cb1cccee7fcfde9c6dbd9571e95fcbfe to your computer and use it in GitHub Desktop.
Save nivir/cb1cccee7fcfde9c6dbd9571e95fcbfe to your computer and use it in GitHub Desktop.
Django Error Secret Key Empty
==>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
execute_from_command_line(sys.argv)
File "//anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "//anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "//anaconda/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "//anaconda/lib/python2.7/site-packages/django/core/management/base.py", line 279, in execute
saved_locale = translation.get_language()
File "//anaconda/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 154, in get_language
return _trans.get_language()
File "//anaconda/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 52, in __getattr__
if settings.USE_I18N:
File "//anaconda/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "//anaconda/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "//anaconda/lib/python2.7/site-packages/django/conf/__init__.py", line 151, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
@nivir
Copy link
Author

nivir commented Nov 8, 2016

Solution of the problem Just like the error says, you have no SECRET_KEY defined. You need to add one to your settings.py.
Django will refuse to start if SECRET_KEY is not set.
You can read more about this setting in the docs.

The SECRET_KEY can be just about anything...but if you want to use Django to generate one, you can do the following from the python shell:

from django.utils.crypto import get_random_string
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
SECRET_KEY = get_random_string(50, chars)
print SECRET_KEY

Copy the SECRET_KEY to your settings file.

Solution link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment