我的代码如何判断它是在Google服务器还是我的本地开发服务器上运行? [英] How can my code tell if it's running on Google's server or my local development server?

查看:169
本文介绍了我的代码如何判断它是在Google服务器还是我的本地开发服务器上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:


是否有一个环境标志会告诉我的代码是在生产环境还是在开发服务器上运行?



我希望能够使用if语句根据此标志执行不同的操作。



(具体案例:换行符在我想阅读的文本文件中,在两种环境下的处理方式不同)。

 如果os.environ.get('SERVER_SOFTWARE','')。startswith('Development'):
DEBUG = True
logging.debug([*] Debug info activated)


Possible Duplicate:
In Python, how can I test if I'm in Google App Engine SDK?

Is there an environment flag that will tell if my code is running in production or on the development server?

I'd like to be able to use an if statement to do something different depending on this flag.

(Specific case: newlines in a text file I want to read are treated differently in the two environments.)

解决方案

if os.environ.get('SERVER_SOFTWARE','').startswith('Development'):
    DEBUG = True
    logging.debug("[*] Debug info activated")

这篇关于我的代码如何判断它是在Google服务器还是我的本地开发服务器上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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