.ini文件加载环境变量 [英] .ini file load environment variable

查看:502
本文介绍了.ini文件加载环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Alembic Flask项目中进行迁移.有一个alembic.ini文件,必须在其中指定数据库配置:

I am using Alembic for migrations implementation in a Flask project. There is a alembic.ini file where the database configs must be specified:

sqlalchemy.url = driver://user:password@host/dbname

是否可以从环境变量中指定参数?我试图以这种方式$(env_var)加载它们,但是没有成功.谢谢!

Is there a way to specify the parameters from the environment variables? I've tried to load them in this way $(env_var) but with no success. Thanks!

推荐答案

我已通过将env.py中的sqlalchemy.url设置为@dirn建议来解决了这个问题.

I've solved the problem by setting sqlalchemy.url in env.py as @dirn suggested.

config.set_main_option('sqlalchemy.url', <db_uri>)达到了目的,可以从环境或配置文件中加载<db_uri>.

config.set_main_option('sqlalchemy.url', <db_uri>) did the trick, where <db_uri> can be loaded from environment or config file.

这篇关于.ini文件加载环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆