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

前端 未结 5 2075
太阳男子
太阳男子 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条回答
  •  旧时难觅i
    2021-01-14 13:56

    Try this instead:

    import os
    import environ
    
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    environ.Env.read_env(env_file=os.path.join(BASE_DIR, '.env'))
    

提交回复
热议问题