2010-05-04 36 views
2

GAE web应用程序允许单个处理程序映射到的路径:如何处理与webapp.RequestHandler链要求

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

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

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

回答

5

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

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

0

我已经找到另一种方式

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