Django.core.exceptions.improperlyconfigured: the secret_key setting must not be empty

In this article let’s discuss about Django.core.exceptions.improperlyconfigured: the secret_key setting must not be empty. Let’s go through the following methods without any delay.

Method 1:

# add SECRET_KEY from terminal (secret_key is collected from django -->settings.py file)
$ export SECRET_KEY='lmrffsgfhrilklg-za7#57vi!zr)ps8)2anyona25###dl)s-#s=7=vn_'
#settings.py
import os
SECRET_KEY = os.environ['SECRET_KEY']

If you are facing any issues with the above approach then try the alternative that is given below. It may look similar by have a try!

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

Hope the above solution works.

Realted Posts : How to change site url github