load .env file if DJANGO_READ_DOT_ENV_FILE is True

This commit is contained in:
Fábio C. Barrionuevo da Luz 2017-01-09 15:35:13 -03:00 committed by GitHub
parent a542a7e51c
commit 2af079f7aa

View File

@ -16,7 +16,21 @@ ROOT_DIR = environ.Path(__file__) - 3 # ({{ cookiecutter.project_slug }}/config
APPS_DIR = ROOT_DIR.path('{{ cookiecutter.project_slug }}') APPS_DIR = ROOT_DIR.path('{{ cookiecutter.project_slug }}')
env = environ.Env() env = environ.Env()
env.read_env()
# Load operating system environment variables and then prepare to use them
env = environ.Env()
# .env file, should load only in development environment
READ_DOT_ENV_FILE = env('DJANGO_READ_DOT_ENV_FILE', default=False)
if READ_DOT_ENV_FILE:
# Operating System Environment variables have precende over variables defined in the .env file,
# that is to say variables from the .env files will only be used if not defined
# as environment variables.
env_file = str(ROOT_DIR.path('.env'))
print('Loading : {}'.format(env_file))
env.read_env(env_file)
print('The .env file has been loaded. See common.py for more information')
# APP CONFIGURATION # APP CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------