8

在我本地的 Google 应用引擎开发环境中,我想使用 ipython shell,尤其是能够检查带有通过 创建的数据的模型dev_server.py,非常类似于 django 的manage.py shell命令的工作方式。

(这意味着应该在sys.path修复并app.yaml读取和分析后启动ipython shell,并且本地数据存储已准备好)

有什么简单的解决方案吗?

4

3 回答 3

7

对于初学者,您可以将应用程序根目录和 SDK 根目录 ( google_appengine) 放在 Python 路径中。您还需要一些库,例如yaml,安装或添加到 SDKlib目录中的库路径。然后您可以导入模块并调用一些功能。

>>> import sys
>>> sys.path.append('/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine')

当然,只要代码路径尝试进行服务调用,库就会引发异常,说它没有绑定到任何东西。要将服务库绑定到测试存根,请使用 testbed 库:

>>> from google.appengine.ext import testbed
>>> tb = testbed.Testbed()
>>> tb.activate()
>>> tb.init_datastore_v3_stub()
>>> from google.appengine.ext import db
>>> import models
>>> m = models.Entry()
>>> m.title = ‘Test’
>>> m.put()

要告诉数据存储测试存根使用您的开发服务器的数据存储文件,请将文件的路径init_datastore_v3_stub()作为datastore_file参数传递给。有关详细信息,请参阅方法的文档注释google.appengine.ext.testbed

有关测试平台的更多信息:https ://developers.google.com/appengine/docs/python/tools/localunittesting

于 2013-01-23T08:26:36.493 回答
1

基本上你需要使用这个:https ://developers.google.com/appengine/articles/remote_api

对于 IPython 支持,您有两种选择:

(1) 如果您使用的是 Python 2.7(和 IPython 0.13),则需要使用它来嵌入 IPython shell:

from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
shell = TerminalInteractiveShell(user_ns=namespace)
shell.mainloop()

(2) 如果您使用的是 Python 2.5(和 IPython 0.10.2),则需要使用这一行来嵌入 IPython shell:

from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(user_ns=namespace, banner=banner)
ipshell()

这是我使用的一个:https ://gist.github.com/4624108所以你只需输入..

>> python console.py your-app-id
于 2013-01-24T16:13:22.117 回答
0

一旦你运行dev_appserver.py 你会得到

starting module "default" running at: http://127.0.0.1:8080
Starting admin server at : http://localhost:8000

所以基本上你想要做的是访问 http://localhost:8000并且在那里你会发现“交互式控制台”你可以用它来玩

于 2015-11-19T06:42:31.693 回答