django 2 not able to load env variables from the .env file to setting.py file

前端 未结 5 1973
太阳男子
太阳男子 2021-01-14 13:08

I tried to load environment variables from a file named .env to settings.py file here i created the .env file and settings file same folder.

this is my .env file

5条回答
  •  孤街浪徒
    2021-01-14 13:57

    For future Googlers here's another approach. Inside manage.py add:

    from dotenv import load_dotenv
    load_dotenv()
    

    Now you can do the following anywhere else in your project (including settings.py) to get access to environment variables:

    import os
    os.environ.get("NAME")
    

提交回复
热议问题