Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Sep 7, 2021
1 parent e231891 commit 6a67a00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Added
- Added Elasticsearch7 to search scheme
`#314 <https://github.com/joke2k/django-environ/pull/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 <https://github.com/joke2k/django-environ/pull/242>`_.

Fixed
+++++
Expand Down
4 changes: 3 additions & 1 deletion docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<tips.html#multiple-env-files>`__.

#. **What (where) is the root part of the project, is it part of the project where are settings?**

Expand Down
42 changes: 18 additions & 24 deletions docs/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 6a67a00

Please sign in to comment.