【问题标题】:How to process request with chain of webapp.RequestHandler如何使用 webapp.RequestHandler 链处理请求
【发布时间】:2010-05-05 12:40:49
【问题描述】:

GAE webapp 允许将单个处理程序映射到路由:

application = webapp.WSGIApplication([
                                     ('/login', gae_handlers.UserLogin),
                                     ], debug=True)

有什么方法可以让我拥有一个请求处理程序链?

我想要在所有其他处理程序运行之前进行身份验证的处理程序。

【问题讨论】:

    标签: google-app-engine authentication web-applications


    【解决方案1】:

    您可以使用装饰器或 WSGI 中间件来做到这一点。

    this answer 中有一个使用装饰器的好例子。 Nick Johnson 的AEoid 项目使用中间件方法。

    【讨论】:

      【解决方案2】:

      我找到了另一种方法

      class ExtendedRequest(google.appengine.ext.webapp.WSGIApplication.REQUEST_CLASS):
          # I can basically do anything here
          def get_session_id(self):
              return self.cookies.get('session_id')
      
      google.appengine.ext.webapp.WSGIApplication.REQUEST_CLASS = ExtendedRequest
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-06
        • 2020-04-18
        • 1970-01-01
        • 1970-01-01
        • 2022-01-20
        • 2016-05-10
        相关资源
        最近更新 更多