From 2af079f7aa8ae480afa7e3a122b9186935274c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20C=2E=20Barrionuevo=20da=20Luz?= Date: Mon, 9 Jan 2017 15:35:13 -0300 Subject: [PATCH 1/5] load .env file if DJANGO_READ_DOT_ENV_FILE is True --- .../config/settings/common.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/common.py b/{{cookiecutter.project_slug}}/config/settings/common.py index c0c86b39..34ff52d9 100644 --- a/{{cookiecutter.project_slug}}/config/settings/common.py +++ b/{{cookiecutter.project_slug}}/config/settings/common.py @@ -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 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 # ------------------------------------------------------------------------------ From 06603dda17a500ba8a63b1184168e0712c43dc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20C=2E=20Barrionuevo=20da=20Luz?= Date: Mon, 9 Jan 2017 15:39:27 -0300 Subject: [PATCH 2/5] fix W291 trailing whitespace on common.py --- {{cookiecutter.project_slug}}/config/settings/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/common.py b/{{cookiecutter.project_slug}}/config/settings/common.py index 34ff52d9..5afa7d99 100644 --- a/{{cookiecutter.project_slug}}/config/settings/common.py +++ b/{{cookiecutter.project_slug}}/config/settings/common.py @@ -24,7 +24,7 @@ env = environ.Env() 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, + # 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')) From b0c771b6457a1c2e1983e78afd27b15193ee5f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20C=2E=20Barrionuevo=20da=20Luz?= Date: Mon, 9 Jan 2017 15:53:30 -0300 Subject: [PATCH 3/5] include DJANGO_READ_DOT_ENV_FILE on env.example --- {{cookiecutter.project_slug}}/env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/{{cookiecutter.project_slug}}/env.example b/{{cookiecutter.project_slug}}/env.example index 66a3570d..138b75fd 100644 --- a/{{cookiecutter.project_slug}}/env.example +++ b/{{cookiecutter.project_slug}}/env.example @@ -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!!! From 10fa9065998346176ec1bb9eedf20a8a4b50105f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20C=2E=20Barrionuevo=20da=20Luz?= Date: Mon, 9 Jan 2017 16:02:53 -0300 Subject: [PATCH 4/5] add DJANGO_READ_DOT_ENV_FILE to settings docs --- docs/settings.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/settings.rst b/docs/settings.rst index eb6e92a4..893a47e9 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -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 +======================================= =========================== ============================================== ====================================================================== ======================================= =========================== ============================================== ====================================================================== From 83900ddfd39818411868ec9d2469ae0151c73baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20C=2E=20Barrionuevo=20da=20Luz?= Date: Fri, 3 Feb 2017 14:12:52 -0300 Subject: [PATCH 5/5] fix typo --- {{cookiecutter.project_slug}}/config/settings/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/common.py b/{{cookiecutter.project_slug}}/config/settings/common.py index 5afa7d99..60ca7e6d 100644 --- a/{{cookiecutter.project_slug}}/config/settings/common.py +++ b/{{cookiecutter.project_slug}}/config/settings/common.py @@ -24,7 +24,7 @@ env = environ.Env() 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, + # 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'))