使App Engine模块正常工作

3 投票
1 回答
845 浏览
提问于 2025-04-18 10:40

我正在学习Google App Engine的模块,但我在本地开发服务器上运行它们时遇到了问题,甚至下载并使用他们的示例应用也没能成功。

根据示例应用,所有发送到/work/mobile的请求应该会被转发到相应的模块。

但是,当我向http://localhost:8080/workhttp://localhost:8080/mobile发送请求时,它返回了404错误。

我通过命令行启动了开发服务器:

dev_appserver.py appengine-modules-helloworld-python-master

然后我得到了:

INFO     2014-06-23 09:39:16,375 sdk_update_checker.py:242] Checking for updates to the SDK.
INFO     2014-06-23 09:39:16,673 sdk_update_checker.py:286] This SDK release is newer than the advertised release.
WARNING  2014-06-23 09:39:16,678 api_server.py:378] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO     2014-06-23 09:39:16,682 api_server.py:171] Starting API server at: http://localhost:61790
INFO     2014-06-23 09:39:16,686 dispatcher.py:182] Starting module "default" running at: http://localhost:8080
INFO     2014-06-23 09:39:16,692 admin_server.py:117] Starting admin server at: http://localhost:8000

根据文档,我应该能看到更多的行,告诉我其他模块正在不同的端口上启动,但我不知道为什么没有看到这些信息。

接着,如果我运行以下代码:

import webapp2
from google.appengine.api import modules

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, webapp2 World!\n%s\n%s' % (modules.get_modules(), modules.get_hostname()))

APP = webapp2.WSGIApplication([('/', MainPage),], debug=True)

结果是:

Hello, webapp2 World!
['default']
localhost:8080

就好像非默认模块没有被加载一样……

那么,正确设置模块并使它们在本地开发服务器和生产环境中都能正常工作的方法是什么呢?

谢谢

1 个回答

3

你的yaml文件里的应用名称写错了。名称应该和你在启动本地服务器时使用的命令一致,也就是dev_appserver.py命令里的appengine-modules-helloworld-python-master。你需要在命令或者yaml文件中把它们改成一致的。

你还需要在开发服务器上启动这些模块:

dev_appserver.py dispatch.yaml app.yaml mobile_frontend.yaml static_backend.yaml

撰写回答