Forums

Issue with environment variables

Hello. I followed this documentation, but when I set up secret key, web-app doesn't work and I get this error:

Error running WSGI application
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

In WSGI-file:

import os
import sys
from dotenv import load_dotenv
project_folder = os.path.expanduser('~/deploy_tkontakta')
load_dotenv(os.path.join(project_folder, '.env'))

When I type in web-console "echo $SECRET_KEY" or "echo $DB_KEY", I get correct values. Also I get it, in web-console-python, via "os.getenv('SECRET_KEY')". But web-app doesn't work. Please give me tips.

hmm, if you run

python /path/to/your/wsgi.py

and then try to get the secret key from there, does that work?

When I run this for my project

python /path/to/your/wsgi.py

I am getting this error:

FileNotFoundError: [Errno 2] No such file or directory: '<project_path>/<secret_file_name>.json'

I also tried giving the full path of this JSON file, but it didn't work either.

Checking this link here shows that I configured the wsgi.py file correctly, but I still couldn't find the root cause for this error.

Solution here seems that it worked for me too. I just changed the file name, and it worked.

Glad to hear that!