django environ plus允许您利用受12个因素启发的环境变量来配置django应用程序。

django-environ-plus的Python项目详细描述


============
django environ plus django environ plus django environ plus django environ plus


>django environ plus允许您使用12个因素激励的环境变量来配置django应用程序。









这个模块e是一个合并体:


>*`envpparse``envparse`\
*`honcho``honcho```dj数据库url``dj搜索url```dj搜索url```dj配置url```dj配置url`````django缓存url``







>*`12factor django``12factor django```12factor django```12factor django``````django`````````两勺django``两勺django``两勺django````的灵感>这是您的"settings.py"文件b在您安装**django environ plus之前**

…代码块::python

import os
site\u root=os.path.dirname(os.path.dirname(os.path.realpath(u file_uu)))


debug=true
template_u debug=debug

databases={
'默认值':{
'引擎':'django.db.backends.postgresql"u psycopg2"、
"名称":"数据库"、
"用户":"用户"、
"密码":"githubbedpassword"、
"主机":"127.0.0.1"、
"端口":"8458"、
}
"额外":{
"引擎":"django.db.backends.sqlite3"、
"name":os.path.join(site_root,'database.sqlite')
}
}


media_url='media/'
static_root=os.path.join(site_root,'static')
static_url='static/'

secret_key='.im令人难以置信的仍然在这里…'

caches={
'默认':{
'后端':'django.core.cache.backends.memcached.memcacheddcache',
'位置':[
'127.0.0.1:11211','127.0.0.1:11212','127.0.0.1:11213',
]
},
'redis':{
'后端':'django-redis.cache.rediscache',
'位置':'127.0.0.1:6379:1',
'选项':{
'客户端类别':'django-redis.client.defaultclient',
'密码':'redis-githubbed密码',
}
}
}


之后:

…代码块::python

import environ
root=environ.path(uu file_uu)-3三个文件夹back(/a/b/c/-3=/)
env=environ.env(debug=(bool,false),)设置默认值并强制转换
environ.env.read_env()reading.env file

site_u root=root()

debug=env('debug')如果不在os.environ中,则为false
template\u debug=debug

databases={
"default":env.db(),如果数据库URL不在os.environ中,则引发不正确的配置异常
"extra":env.db('sqlite\u url',default='sqlite:///tmp/my tmp sqlite.db')
}


public_root=root.path('public/')


media_root=public_root('media')
media_url='media/'
static_root=public_root('static')
static_url='static/'

secret key=env('secret_key')引发不正确的配置异常。如果secret_key不在os.environ中

caches={
"default":env.cache(),
"redis":env.cache('redis_url')
}


代码块::bash

debug=on
django_settings_module=myapp.settings.dev
secret_key=your secret key
database_url=psql://urser:un githubbedpassword@127.0.0.1:8458/database
sqlite_url=sqlite:///my local sqlite.db
cache_url=memcache://127.0.0.1:11211127.0.0.1:11212127.0.0.1:11213
redis_url=rediscache://127.0.0.1:6379:1?client_class=django_redis.client.defaultclient&;password=redis un githubbed password



如何安装
===





$pip安装django environ plus



==


代码块::python

>;>;import environ
>;>;env=environ.env(
debug=(bool,false),

>;>;env('debug')
false
>;>;env('debug',default=true)
true

>;>;打开('.myenv'一','a').write('debug=on')
>>gt;环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境(环境-环境-环境-环境-环境-环境-环境-环境-环境(环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境(环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境(环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境(环境-环境-环境-环境-环境-环境-环境-环境-环境-环境-环境_var')
1010,'1010'

>;>>打开('.my env','a')。写入('\nDatabase_url=sqlite:///my local sqlite.db')
>;>>环境读取环境('.myenv')
>;>env.db()
{engine':'django.db.backends.sqlite3','name':'my local sqlite.db','host':','user':','password':','p


>
>>>gt>gt;root=env.path('/home/myproject/'/home/myproject/myproject/')
>>gt;root('static')
'/home/myproject/static'/home/myproject/static'


>





>










>
>

>
>>









br/>-元组(foo=(a,b,c)).
-dict(bar=key=val,foo=bar)环境环境(bar=(dict,{}}))
-dict(bar=key=val;foo=1.1;baz=true)环境环境(bar=(dict(value=unicode,cast=dict(foo=float,baz=bool)),{})环境(bar=(dict(value=unicode,cast=unicode,cast=dict(foo=float,baz=bool)),{}])
-url
-url(environ.path)
-db-url
-db-db-url
-postgresqsql:postgresgres://,postgresgres://,postgresgres://pgsql://、psql:/或postgresql:。//
-postgis:postgis://
-mysql:mysql://or mysql2://
-mysql for geodjango:mysqlgis://
-sqlite:sqlite://
-sqlite with spatialite for geodjango:spatialite://
-oracle:oracle://
-ldap:ldap://
-cache-url
-database:dbcache://
-dummy:dummycache://
-file:filecache://
-memory:locmemcache://
-memcached:memcache://
-python memcache:pymemcache://
-redis:rediscache://
-搜索url
-elasticsearch:elasticsearch://
-solr:solr://
-whoosh:whoosh://
-xapian:xapian://
-简单缓存:简单://
-电子邮件地址
-smtp:smtp://
-smtp+ssl:smtp+ssl://
-smtp+tls:smtp+tls://
-控制台邮件:控制台电子邮件://
-文件邮件:file mail://
-locmem邮件:memorymail:。//
-虚拟邮件:dummy mail://

tips
====


在url中使用不安全字符
=-


要使用不安全字符,必须在设置到`.env``文件之前使用``urllib.parse.encode``编码。

代码块:

database_URL=mysql://user:%23password@127.0.0.1:3306/dbname



请参阅https://elostablepress.com/stop-using-unsafe-characters-in-url/以获取参考。

S代码:

…代码块::python

email-config=env.email-url(
'email-url,默认值为smtp://user@:password@localhost:25')





tests
==



$cd-django environ/
$python setup.py test




license
==



`0.0.1`-2019年2月18日` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `---———————————————————-------------------------------------
-将不安全字符修复到url
-澄清丢失或不可读文件的警告。感谢@nickcatal
-添加对django 1.10的支持。
-修复对oracle url的支持
-修复对django redis的支持


`0.4.0-2015年9月23日<;https://github.com/joke2k/django environ/compare/v0.3…v0.4>;`\uuuu
-----------------------------------
-fix非ascii值(在python 2.x中损坏)
-新的电子邮件方案-smtp+ssl和smtp+tls(smtps将被弃用)
-redis_cache替换为django_redis
-添加元组支持。感谢@anonymouzz
-添加对数据库(django ldapdb)的ldap url支持
-修复psql/pgsql url

`0.3-2014年6月3日<;https://github.com/joke2k/django environ/compare/v0.2.1…v0.3>;`\uuuuxub
----------添加缓存url支持
-添加电子邮件URL支持
-添加搜索URL支持
-重写自述文件。rst

0.2.1 2013年4月19日
----
-环境/环境.py:env.\u call\uu现在使用env.get\u value实例方法

0.2 2013年4月16日
----
-环境/环境.py,环境/test.py,环境/test\env.txt:add advanced
float p纵火(用逗号和点符号分隔千位小数和小数)
-readme.rst,docs/index.rst:fix-typo in documentation

>0.1 2013-4-2013-4-02
-
-
-initial release


credits
===


-`12factor django ``12factor django ``12 factor django `
-`django ``两勺django ``2勺django `
br/>-`rconradharris ``rconradharris ` ` ` ` ` `u
-` dj数据库url ``dj数据库```dj数据库url ``dj数据库```dj数据库```dj数据库` ` ` ` `migoonzalzalvar` ` ` dj电子邮件地址` ` ` ` ` ` ` ` ` ghickman` ` ` django缓存url ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `/>-‘现代包装模板’_ rconradharris:https://github.com/rconradharris
。_环境解析:https://github.com/rconradharris/envparse

…_ kennethreitz:https://github.com/kennethreitz
…_ DJ-database-url:https://github.com/kennethreitz/DJ数据库url

…_ migonzalvar:https://github.com/migonzalvar
。_ DJ-email-url:https://github.com/migonzalvar/DJ电子邮件url

…_ Ghickman:https://github.com/Ghickman
。_ django-cache-url:https://github.com/ghickman/django-cache-url

…_ Julianwachholz:https://github.com/julianwachholz
。_ DJ-config-url:https://github.com/julianwachholz/dj-config-url

…_ dstufft:https://github.com/dstufft
。_ DJ-SEARCH-URL:https://github.com/dstufft/DJ搜索URL

…_ nickstenning:https://github.com/nickstenning
。_本周:https://github.com/nickstenning/honcho

…_ 12因素:http://www.12factor.net/
…_ 12factor-django:http://www.wellfireinteractive.com/blog/easier-12-factor-django/
。_`两勺django`:http://twoscooppress.org/

…_分发:http://pypi.python.org/pypi/distribute
…_`现代包模板:http://pypi.python.org/pypi/modern package template

…| pypi图像::https://img.shields.io/pypi/v/django-environ.svg?style=flat square&;label=version
:目标:https://pypi.python.org/pypi/django environ
:alt:pypi上发布的最新版本

…|覆盖范围图像::https://img.shields.io/covertalls/joke2k/django-environ/master.svg?style=flat square
:目标:https://covertalls.io/r/joke2k/django-environ?branch=master
:alt:测试覆盖率

…| Unix构建图像::https://img.shields.io/travis/joke2k/django-environ/master.svg?style=flat square&;label=unix%20build
:目标:http://travis ci.org/joke2k/django environ
:alt:Mac/Linux上主分支的生成状态

。| Windows构建IMAGE::https://img.shields.io/appveyor/ci/joke2k/django-environ.svg?style=flat square&;label=windows%20build
:目标:https://ci.appveyor.com/project/joke2k/django environ
:alt:windows上主分支的生成状态

。|下载图像::https://img.shields.io/pypi/dm/django-environ.svg?style=flat square
:目标:https://pypi.python.org/pypi/django environ
:alt:每月下载

…|许可证图像::https://img.shields.io/badge/license-mit-blue.svg?style=flat square
:目标:https://raw.githubusercontent.com/joke2k/django environ/master/license.txt
:alt:package license

……_许可证:https://github.com/joke2k/django environ/blob/master/license.txt

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java需要在环境或系统属性中指定类名,或者作为小程序参数,或者在应用程序资源文件[springtest]中指定类名   使用流映射java 8转换另一个列表中的列表   docusignapi如何使用java将信封状态更改为“void”?   java Hibernate“提供的id类型错误,预期为Long,Get class DelayedPostInsertIdentifier”异常   升级Tomcatembed版本后java Basic登录身份验证失败   java如何将第三个元素作为循环从数组中删除?   playframework 2.0注销流程正在运行!框架2.0,java   java如何读取hadoop顺序文件?   java如何循环json并在上下文中发布每个索引   爪哇树深度   java多线程场景中的多线程列表更新   java遗传算法:请求优化   java jersey http客户端自定义请求方法   Ubuntu 12.04上带有openjdk 6的java NullPointerException   java如何获取页面上动态显示的复选框的ID   如果以D/M而不是DD/MM的形式输入日期或月份,则将前导零添加到日期字段   java Apache Oltu+Microsoft Integration OAuthProblemException{error='invalid_request',description='missing required parameters',包含无效的   java JsonWriter IOException不完整文档   java无法对非静态字段(操作侦听器)进行静态引用