Issue
I'm setting up Django using os.getenv
to prepare it for deploying using Docker but it seems it is not reading the .env
file. Any idea why is not reading it?
Here is the setup:
.env
SECRET_KEY=foo
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
settings.py
abstraction
import os
from pathlib import Path
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = os.getenv('SECRET_KEY')
DEBUG = os.getenv('DEBUG')
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS')
Solution
To get environment variables from docker or from the AWS Elastic Beanstalk i use
os.environ.get('SECRET_KEY')
, this is generally more reliable than os.environ['SECRET_KEY']
Answered By - Beikeni
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.