close

[Solved] Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty Error Occurs?

Today I get the following error Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty in python.

How To Solve Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty Error ?

  1. How To Solve Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty Error ?

    To Solve Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty Error So it works and when you do from base import *, it imports SECRET_KEY into your development.py.

  2. Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty

    To Solve Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty Error So it works and when you do from base import *, it imports SECRET_KEY into your development.py.

Solution 1

It starts working because on the base.py you have all information needed in a basic settings file. You need the line:

SECRET_KEY = '8lu*6g0lg)9z!ba+a$ehk)xt)x%rxgb$i1&022shmi1jcgihb*'

So it works and when you do from base import *, it imports SECRET_KEY into your development.py.

You should always import basic settings before doing any custom settings.


EDIT: Also, when django imports development from your package, it initializes all variables inside base since you defined from base import * inside __init__.py

Solution 2

I had the same error and it turned out to be a circular dependency between a module or class loaded by the settings and the settings module itself. In my case it was a middleware class which was named in the settings which itself tried to load the settings.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read