How can I detect Heroku's environment?

前端 未结 7 1659
Happy的楠姐
Happy的楠姐 2020-12-24 05:40

I have a Django webapp, and I\'d like to check if it\'s running on the Heroku stack (for conditional enabling of debugging, etc.) Is there any simple way to do this? An envi

7条回答
  •  离开以前
    2020-12-24 06:15

    Read more about it here: https://devcenter.heroku.com/articles/config-vars

    My solution:

    $ heroku config:set HEROKU=1
    

    These environment variables are persistent – they will remain in place across deploys and app restarts – so unless you need to change values, you only need to set them once.

    Then you can test its presence in your app.:

    >>> 'HEROKU' in os.environ
    True
    

提交回复
热议问题