My favorites | 中文(简体) | Sign in

概述

App Engine 支持任何采用 CGI 接口的 Python 应用程序。网络应用程序框架可以通过处理接口的详细信息来简化开发过程,让您更加专注在应用程序功能的设计上。App Engine 包括一种名为 webapp 的简单网络应用程序框架。

webapp 是一种与 WSGI 兼容的框架。您可以使用 CGI 适配器(例如 Python 标准库提供的适配器)将 webapp 或任何其他 WSGI 框架与 App Engine 配合使用。

此处是一个将 CGI 适配器与 App Engine 配合使用的简单 webapp 应用程序:

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
  def get(self):
    self.response.headers['Content-Type'] = 'text/plain'
    self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication([('/', MainPage)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()