如何检测Heroku的环境? [英] How can I detect Heroku's environment?

查看:136
本文介绍了如何检测Heroku的环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django webapp,我想检查它是否在Heroku堆栈上运行(用于条件启用调试等)有没有什么简单的方法呢?一个环境变量,可能吗?



我知道我可能也可以这样做 - 也就是说,它是否检测到它是否在开发机器上运行,但是只是不是声音正确。

解决方案

ENV var似乎是最明显的做法。或者寻找一个你知道存在的ENV var,或设置自己的:

  on_heroku = False 
如果YOUR_ENV_VAR 'in os.environ:
on_heroku = True

more at: http://devcenter.heroku.com/articles/config-vars


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 environment variable, perhaps?

I know I can probably also do it the other way around - that is, have it detect if it's running on a developer machine, but that just doesn't "sound right".

解决方案

An ENV var seems to the most obvious way of doing this. Either look for an ENV var that you know exists, or set your own:

on_heroku = False
if 'YOUR_ENV_VAR' in os.environ:
  on_heroku = True

more at: http://devcenter.heroku.com/articles/config-vars

这篇关于如何检测Heroku的环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆