What is the use of python-dotenv?

后端 未结 2 2042
旧巷少年郎
旧巷少年郎 2020-12-23 13:34

Need an example and please explain me the purpose of python-dotenv.
I am kind of confused with the documentation.

2条回答
  •  没有蜡笔的小新
    2020-12-23 14:05

    In addition to @Will's answer, the python-dotenv module comes with a find_dotenv() that will try to find the .env file.

    # settings.py
    import os
    from dotenv import load_dotenv, find_dotenv
    
    load_dotenv(find_dotenv())
    
    SECRET_KEY = os.environ.get("SECRET_KEY")
    DATABASE_PASSWORD = os.environ.get("DATABASE_PASSWORD")
    

提交回复
热议问题