Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Django.core.exceptions.improperlyconfigured: the secret_key setting must not be empty - simple solution when encountering the error
Next
Answered
Hadassah O'Brien
  • 26
Hadassah O'Brien
Asked: May 17, 20222022-05-17T13:54:31+00:00 2022-05-17T13:54:31+00:00In: python

Django.core.exceptions.improperlyconfigured: the secret_key setting must not be empty – simple solution when encountering the error

  • 26

. 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!

django.core.exceptions.improperlyconfigured
  • 2 2 Answers
  • 148 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-05T16:57:30+00:00Added an answer on June 5, 2022 at 4:57 pm

    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.

    • 11
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Zoé Maury
    2022-05-25T20:02:36+00:00Added an answer on May 25, 2022 at 8:02 pm

    After reorganizing the settings according to Daniel Greenfield’s book Two scoops Django, I encountered the same problem.

    I solved the problem by setting

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings.local")

    In manage.py or wsgi.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:

    settings/
     __init__.py
     base.py
     local.py
     prod.py
     stage.py

    Keep the following code in your settings/__init__.py

    from .base import *
    
    env_name = os.getenv('ENV_NAME', 'local')
    
    if env_name == 'prod':
     from .prod import *
    elif env_name == 'stage':
     from .stage import *
    else:
     from .local import *
    • 6
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.