python-dotenv

项目地址:https://github.com/theskumar/python-dotenv

安装

  1. pip install -U python-dotenv

使用

  1. # settings.py
  2. from dotenv import load_dotenv
  3. load_dotenv()
  4. # OR, the same with increased verbosity:
  5. load_dotenv(verbose=True)
  6. # OR, explicitly providing path to '.env'
  7. from pathlib import Path # python3 only
  8. env_path = Path('.') / '.env'
  9. load_dotenv(dotenv_path=env_path)