Forums

Error "The SECRET_KEY setting must not be empty." after workflow with dotenv

Hello, I would like to ask you for your help since I ran out of ideas. I am trying to set up a .env workflow with secret key for Django. I thought that I set up everything correctly (since web app was working properly) but today I wanted to run :

"python manage.py collectstatic"

and I got this error:

raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

I double checked everything with WSGI, my settings.py my .env file. Everything looks like it should (or at least I think that). I was checking almost random things since I receive very little information with this error but right now I run out of ideas.

I am not sure if Django cannot find .env file? It cannot read that file?

I will be really grateful for any tips and directions.

Thank you

@Edit: I am really sorry for all the commotion. I got it.

My mistake was, than when I was following instructions, I didn't apply last section: https://help.pythonanywhere.com/pages/environment-variables-for-web-apps/ called "postactivate script".

If you found this after and you have the same problem, make sure that you get printed out your Secret Key when you type in in your console "echo $SECRET_KEY".

Did you load the env file in the console that you're running the command in?

That was exactly my mistake. I am sorry.

I edited my post if someone will find it while encountering this problem :-)

Glad you got there in the end :-)