模块介绍:
Reads the key,value pair from .env file and adds them to environment variable.
Do one thing, do it well!
pypi:
https://pypi.org/project/python-dotenv/
github:
https://github.com/theskumar/python-dotenv
安装
pip install python-dotenv
使用示例
.env配置文件
FLASK_ENV=development FLASK_DEBUG=1
读取示例
from dotenv import find_dotenv, load_dotenv import os # 1、读取.env文件并设置环境变量 load_dotenv(find_dotenv()) # 2、从环境变量中读取值 print(os.environ.get("FLASK_ENV")) # development print(os.environ.get("FLASK_DEBUG")) # 1