Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Abstract
3--------
5There are lots of ways of dealing with configuration data that should not be hard-coded (and potentially) revealed in
6the ``settings.py`` file. Using environment variables, though recommended by lots of people, is not always possible;
7they do not work in Apache and may not work with Nginx.
9Two notable solutions are `django-configurations`_ and `django-environ`_, and developers are encouraged to check these
10out. SuperDjango offers the ``env`` app as a relatively straight-forward means of dealing with configuration data.
12.. _django-configurations: https://github.com/jazzband/django-configurations
13.. _django-environ: https://github.com/joke2k/django-environ
15Install
16-------
18No installation steps are required to use this package, but see Usage below.
20Usage
21-----
23Create an ``env.ini`` file in your source directory. This is typically the same directory as the ``manage.py`` file.
25.. important::
26 Be sure to exclude this file from your repo.
28Here is an example:
30.. code-block:: ini
32 [environment]
33 name = live
34 debug = True
36 [branding]
37 copyright = ACME, Inc.
38 logo = images/logo.png
39 site_title = ACME Technologies
40 tagline = Rocket skates, explosive birdseed, and more since 1955.
42 [secret]
43 key = secret_key
45 [database]
46 host = localhost
47 name = example_com
48 password = None
49 user = postgres
51 [log]
52 level = DEBUG
53 path = /path/to/work/example_com/logs
55Each section becomes available as an instance variable on the Env instance, meaning (for example) that the database host
56may be referred to as ``env.database.host``.
58.. tip::
59 Any variable added to the ``environment`` section is available *without* the use of the environment section name.
60 For example, ``env.debug`` instead of ``env.environment.debug``. See example below.
62In your ``settings.py`` file, import :py:class:`Env` and load the INI file:
64.. code-block:: python
66 # settings.py
67 from superdjang.env import Env
69 # assuming the file is located at the same level as manage.py ...
70 env = Env("env.ini")
72 DEBUG = env.debug
73 SECRET_KEY = env.secret.key
75 DATABASES = {
76 'default': {
77 'ENGINE': 'django.db.backends.postgresql',
78 'HOST': env.database.host,
79 'NAME': env.database.name,
80 'PASSWORD': env.database.password,
81 'USER': env.database.user,
82 }
83 }
85 BRANDING = env.branding
87 # ... and so on ...
89"""
90__author__ = "Shawn Davis <shawn@superdjango.com>"
91__maintainer__ = "Shawn Davis <shawn@superdjango.com>"
92__version__ = "0.4.0-x"
94from .library import *
96__all__ = (
97 "Env",
98)