我在一个应用程序引擎项目中,我想在其中添加一个指向 Javascript 测试运行程序的链接,我希望该链接仅在运行开发服务器时存在。我在本地 shell 上进行了一些实验,使用 NoseGAE 中的技术加载配置,而不是在“App Engine 控制台”[1] 上实时加载配置,在我看来,真实实例和开发服务器之间的区别在于存在模块 google.appengine.tools
。这让我想到了这个效用函数:
def is_dev():
"""
Tells us if we're running under the development server or not.
:return:
``True`` if the code is running under the development server.
"""
try:
from google.appengine import tools
return True
except ImportError:
return False
问题(最后!)是:这是个坏主意吗?在这种情况下,谁能提出更好的方法?
[1] http://con.appspot.com/console/ (试试吧!确实非常方便)
最佳答案
开发服务器的标准测试方式如下:
DEBUG = os.environ['SERVER_SOFTWARE'].startswith("Dev")
依赖特定模块的存在或不存在——尤其是未记录的模块——可能不是一个好主意。
关于python - 关于在开发服务器上运行与应用程序引擎(python)中的真实实例相比的这种假设的评论?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3031886/