.ini文件加载环境变量 [英] .ini file load environment variable
问题描述
我正在使用 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屋!