【django-environ学习】官方说明: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')}
.envDJANGO_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
推荐阅读
- 1分钟完成在线测试部署便捷收集班级同学文件的web管理系统
- 【英国好物推荐】 图一是E45乳膏,英国专门用来缓解皮肤干燥
- 新英雄杀怎么玩(英雄杀18层塔攻略)
- 华为matex2参数_华为matex2参数配置详情
- 游戏工作室怎么赚钱(搬砖一天收入300)
- 上 学习ASP.NET Core Blazor编程系列十——路由
- 【lwip】10-ICMP协议&源码分析
- 创造与魔法2022最新礼包在哪里领取
- 奥比岛手游被频繁投诉的是哪支施工队
- 琉璃神社app有苹果的吗