Gunicorn Environment Variable Setting

后端 未结 3 1979
说谎
说谎 2021-02-02 16:42

I\'m currently having difficulty passing environment variables into Gunicorn for my Django project. I\'m on the latest 19.1 version. I have a wsgi.py file like so:



        
3条回答
  •  日久生厌
    2021-02-02 17:00

    You just have to export your environment variable.

    export SERVER_ENV=TEST
    export SERVER_ID=TEST
    gunicorn -b 127.0.0.1:8080 --error-logfile - --access-logfile - app.wsgi:application
    

    And in your code you can get them like that

    os.getenv('SERVER_ENV')
    

提交回复
热议问题