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

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

问题描述

我有一个 Django webapp,我想检查它是否在 Heroku 堆栈上运行(用于有条件地启用调试等)有什么简单的方法可以做到这一点?也许是环境变量?

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".

推荐答案

ENV var 似乎是最明显的方法.要么查找您知道存在的 ENV 变量,要么设置您自己的:

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

更多信息:http://devcenter.heroku.com/articles/config-vars

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

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