简体   繁体   中英

How to load .env file for different environments in python?

我有本地、开发和生产环境的三个 .env 文件,我必须在为该服务器进行部署时加载特定的环境文件,即如果我在进行 DEV 部署,那么 dev .env 文件应该全部加载。

You can use the pip module python-dotenv to load .env files.
Here's what you need to do:

from dotenv import load_dotenv

load_dotenv(some_path)

Now the vars in the env file located at some_path can be used with os.getenv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM