【问题标题】:Basics of Google App Engine: get() method of handlerGoogle App Engine 基础:处理程序的 get() 方法
【发布时间】:2014-03-11 22:36:15
【问题描述】:

我正在学习 Udacity 网络编程教程 (https://www.udacity.com/wiki/cs253/unit_2#submitting-input)。

在 Google App Engine 中,我们有一个名为 main.py 的文件。

这是一个非常基本的“main.py”的代码

import webapp2

form = """
<form action="http://www.google.com/search">
    <input name="q">
    <input type="submit">
</form>
"""

class MainPage(webapp2.RequestHandler):
    def get(self):
        #self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write(form)

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

我查看了 webapp2 源代码 (https://code.google.com/p/webapp-improved/source/browse/webapp2.py),发现 RequestHandler 类中的 get() 方法没有定义。

源代码中的什么地方说必须定义处理程序的 get(self) 方法?我知道我无法理解 GAE 的所有细节,但很高兴看到它在哪里指定。

【问题讨论】:

    标签: python django google-app-engine


    【解决方案1】:

    不需要定义 get 方法。仅当您想提供 HTTP GET 请求时才需要。

    勾选这一行,获取与http请求对应的方法的引用 https://code.google.com/p/webapp-improved/source/browse/webapp2.py#555

    这条线正在调用它 https://code.google.com/p/webapp-improved/source/browse/webapp2.py#570

    所以如果你有get方法并且有get请求,第555行的方法会指向你定义的get函数,第570行会调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-21
      • 2017-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-19
      • 2015-05-29
      • 1970-01-01
      相关资源
      最近更新 更多