假设我们要添加一个我们自己的Middleware,用来记录每次请求的日志
下面就是一个符合规范的Middleware, 构造函数中接受一个WSGI APP, call返回一个WSGI APP.
复制代码 代码如下:
class LoggerMiddleware(object):
'''WSGI middleware'''
def __init__(self, application):
self.app = application
def __call__(self, environ, start_response):
# write logs
try:
return self.app(environ, start_response)
except Exception, e:
# write logs
pass
finally:
# write logs
pass
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8