mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-23 01:57:03 +03:00
Merge pull request #985 from pydanny/dot_env_issue
load .env file from root dir only if DJANGO_READ_DOT_ENV_FILE is True
This commit is contained in:
commit
69bc96d9ba
|
@ -3,7 +3,14 @@ Settings
|
|||
|
||||
This project relies extensively on environment settings which **will not work with Apache/mod_wsgi setups**. It has been deployed successfully with both Gunicorn/Nginx and even uWSGI/Nginx.
|
||||
|
||||
For configuration purposes, the following table maps environment variables to their Django setting:
|
||||
For configuration purposes, the following table maps environment variables to their Django setting and project settings:
|
||||
|
||||
|
||||
======================================= =========================== ============================================== ======================================================================
|
||||
Environment Variable Django Setting Development Default Production Default
|
||||
======================================= =========================== ============================================== ======================================================================
|
||||
DJANGO_READ_DOT_ENV_FILE READ_DOT_ENV_FILE False False
|
||||
======================================= =========================== ============================================== ======================================================================
|
||||
|
||||
|
||||
======================================= =========================== ============================================== ======================================================================
|
||||
|
|
|
@ -16,7 +16,21 @@ ROOT_DIR = environ.Path(__file__) - 3 # ({{ cookiecutter.project_slug }}/config
|
|||
APPS_DIR = ROOT_DIR.path('{{ cookiecutter.project_slug }}')
|
||||
|
||||
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 precedence 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
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -4,6 +4,7 @@ POSTGRES_PASSWORD=mysecretpass
|
|||
POSTGRES_USER=postgresuser
|
||||
|
||||
# General settings
|
||||
# DJANGO_READ_DOT_ENV_FILE=True
|
||||
DJANGO_ADMIN_URL=
|
||||
DJANGO_SETTINGS_MODULE=config.settings.production
|
||||
DJANGO_SECRET_KEY=CHANGEME!!!
|
||||
|
|
Loading…
Reference in New Issue
Block a user