diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1f4053e6..d99fbec5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,8 +16,6 @@ Added - Added Elasticsearch7 to search scheme `#314 `_. - Added the ability to use ``bytes`` or ``str`` as a default value for ``Env.bytes()``. -- Added the ability to use env variable pointing to a ``.env`` file - `#242 `_. Fixed +++++ diff --git a/docs/getting-started.rst b/docs/getting-started.rst index d44724b9..d0d5473f 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -114,7 +114,9 @@ FAQ ``django-environ`` will try to get and read ``.env`` file from the project root if you haven't specified the path for it when call ``read_env``. However, this is not the recommended way. When it is possible always specify - the path tho ``.env`` file. + the path tho ``.env`` file. Alternatively, you can use a trick with a + environment variable pointing to the actual location of .env file. + For details see ``__. #. **What (where) is the root part of the project, is it part of the project where are settings?** diff --git a/docs/tips.rst b/docs/tips.rst index 0fe21141..b743cfa7 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -122,14 +122,30 @@ Values that being with a ``$`` may be interpolated. Pass ``interpolate=True`` to Multiple env files ================== -It is possible to have multiple env files and select one using environment variables. +There is an ability point to the .env file location using an environment +variable. This feature may be convenient in a production systems with a +different .env file location. + +The following example demonstrates the above: + +.. code-block:: shell + + # /etc/environment file contents + DEBUG=False + +.. code-block:: shell + + # .env file contents + DEBUG=True .. code-block:: python env = environ.Env() env.read_env(env.str('ENV_PATH', '.env')) -Now ``ENV_PATH=other-env ./manage.py runserver`` uses ``other-env`` while ``./manage.py runserver`` uses ``.env``. + +Now ``ENV_PATH=/etc/environment ./manage.py runserver`` uses ``/etc/environment`` +while ``./manage.py runserver`` uses ``.env``. Using Path objects when reading env @@ -155,25 +171,3 @@ It is possible to use of ``pathlib.Path`` objects when reading environment file env.read_env(os.path.join(BASE_DIR, '.env')) env.read_env(pathlib.Path(str(BASE_DIR)).joinpath('.env')) env.read_env(pathlib.Path(str(BASE_DIR)) / '.env') - - -Using an environment variable to point to a .env file -===================================================== - -Since v0.7.0 there is an ability to set an environment variable ``ENV_FILE`` -to point to the .env file location. It can be convenient in a production -systems with a different .env file location. - -The following example demonstrates the above: - -.. code-block:: shell - - # .secret file contents - SOME_VAR=3.14 - -.. code-block:: console - - $ export ENV_FILE=$(pwd)/.secret - $ python -c 'from environ.environ import Env; Env.read_env(); print(Env.ENVIRON["SOME_VAR"])' - 3.14 -