I am trying to set environment variables in my Python 3 virtual environment, by setting them in the activate file. (I am setting them for my development environment in this case.)
Having activated the virtualenv (env/scripts/activate), seeing "(venv)" at the beginning of my powershell lines, I run:
python manage.py runserver
In the manage.py file I have specified the settings file to use. And the content of that settings file I will show down below in this post.
The variables are meant to be passed to my Django application, but I get the following error:
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
Searching the internet, and mainly SO, I find different approaches to setting environment variables, but each gives the same error. So I wonder what I am doing wrong.
What I have tried:
It seems I have to set the environment variables in the 'activate.bat' file located at env/scripts/activate.bat
. I have tried different ways of doing this, and I have tried the same ways in this file: env/scripts/activate
(without the .bat extension), just to be sure.
I have tried adding lines of the formats found below, to the end of the activate files:
set "SECRET_KEY=^af*$gsdgaGJA4gg($g134FADGJ"
set SECRET_KEY=^af*$gsdgaGJA4gg($g134FADGJ
export SECRET_KEY="^af*$gsdgaGJA4gg($g134FADGJ"
(I have not actually used the secret key as found above, but one generated by Django itself, this one is for demonstration purposes only and doesn't meet Django's requirements.)
My settings.py file
In my settings.py file I have this line to get the SECRET_KEY:
SECRET_KEY = os.environ['SECRET_KEY']
I have decided not to post the full settings.py file since it seems unnecessary.