•  


GitHub - joke2k/django-environ: Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.
Skip to content

Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.

License

Notifications You must be signed in to change notification settings

joke2k/django-environ

Repository files navigation

django-environ

Latest version released on PyPi Coverage Status CI Status Sponsors on Open Collective Backers on Open Collective Say Thanks! Package license

django-environ is the Python package that allows you to use Twelve-factor methodology to configure your Django application with environment variables.

For that, it gives you an easy way to configure Django application using environment variables obtained from an environment file and provided by the OS:

import
 environ

import
 os


env
 =
 environ
.
Env
(
    
# set casting, default value

    DEBUG
=
(
bool
, 
False
)
)

# Set the project base directory

BASE_DIR
 =
 os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))

# Take environment variables from .env file

environ
.
Env
.
read_env
(
os
.
path
.
join
(
BASE_DIR
, 
'.env'
))

# False if not in os.environ because of casting above

DEBUG
 =
 env
(
'DEBUG'
)

# Raises Django's ImproperlyConfigured

# exception if SECRET_KEY not in os.environ

SECRET_KEY
 =
 env
(
'SECRET_KEY'
)

# Parse database connection url strings

# like psql://user:pass@127.0.0.1:8458/db

DATABASES
 =
 {
    
# read os.environ['DATABASE_URL'] and raises

    # ImproperlyConfigured exception if not found

    #

    # The db() method is an alias for db_url().

    'default'
: 
env
.
db
(),

    
# read os.environ['SQLITE_URL']

    'extra'
: 
env
.
db_url
(
        
'SQLITE_URL'
,
        
default
=
'sqlite:////tmp/my-tmp-sqlite.db'

    )
}

CACHES
 =
 {
    
# Read os.environ['CACHE_URL'] and raises

    # ImproperlyConfigured exception if not found.

    #

    # The cache() method is an alias for cache_url().

    'default'
: 
env
.
cache
(),

    
# read os.environ['REDIS_URL']

    'redis'
: 
env
.
cache_url
(
'REDIS_URL'
)
}

The idea of this package is to unify a lot of packages that make the same stuff: Take a string from os.environ , parse and cast it to some of useful python typed variables. To do that and to use the 12factor approach, some connection strings are expressed as url, so this package can parse it and return a urllib.parse.ParseResult . These strings from os.environ are loaded from a .env file and filled in os.environ with setdefault method, to avoid to overwrite the real environ. A similar approach is used in Two Scoops of Django book and explained in 12factor-django article.

Using django-environ you can stop to make a lot of unversioned settings_*.py to configure your app. See cookiecutter-django for a concrete example on using with a django project.

Feature Support

  • Fast and easy multi environment for deploy
  • Fill os.environ with .env file variables
  • Variables casting
  • Url variables exploded to django specific package settings
  • Optional support for Docker-style file based config variables (use environ.FileAwareEnv instead of environ.Env )

Project Information

django-environ is released under the MIT / X11 License , its documentation lives at Read the Docs , the code on GitHub , and the latest release on PyPI .

It’s rigorously tested on Python 3.6+, and officially supports Django 1.11, 2.2, 3.0, 3.1, 3.2, 4.0, 4.1 and 4.2.

If you'd like to contribute to django-environ you're most welcome!

Support

Should you have any question, any remark, or if you find a bug, or if there is something you can't do with the django-environ , please open an issue .

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본