官方说明:https://django-environ.readthedocs.io/en/latest/index.html
installpip install django-environ
quick startimport environimport osenv = environ.Env(# set casting, default valueDEBUG=(bool, False))# Set the project base directoryBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# Take environment variables from .env fileenviron.Env.read_env(os.path.join(BASE_DIR, '.env'))# False if not in os.environ because of casting aboveDEBUG = env('DJANGO_DEBUG')# Raises Django's ImproperlyConfigured# exception if SECRET_KEY not in os.environSECRET_KEY = env('DJANGO_SECRET_KEY')# Parse database connection url strings# like psql://user:pass@127.0.0.1:8458/dbDATABASES = {# 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')}
.env【django-environ学习】DJANGO_DEBUG=TrueDJANGO_SECRET_KEY=your-secret-keyDATABASE_URL=psql://user:un-githubbedpassword@127.0.0.1:8458/databaseSQLITE_URL=sqlite:///my-local-sqlite.dbCACHE_URL=memcache://127.0.0.1:11211,127.0.0.1:11212,127.0.0.1:11213REDIS_URL=rediscache://127.0.0.1:6379/1?client_class=django_redis.client.DefaultClient&password=ungithubbed-secret
经验总结扩展阅读
- 12306有没有候补不成功的
- 联想拯救者R7000 2021款官方配置_联想拯救者R7000 2021款升级情况
- MFC 学习笔记
- day11-Servlet01
- 上 学习ASP.NET Core Blazor编程系列十——路由
- JVM学习笔记——类加载和字节码技术篇
- 嘉年华官方网站|嘉年华邮购中心
- shardingsphere-jdbc 水平分表学习记录
- 再推荐几个适合小孩子的英语学习网站
- Agda学习笔记1