234.10.flask-中间件
作者:互联网
1.中间件
# coding=utf-8
from flask import Flask
app = Flask(__name__)
app.config.from_object("settings.DevelopmentConfig")
@app.route("/index", methods=["POST", "GET"])
def index():
return "index"
class Middleware(object):
def __init__(self, wsgi_app):
"""服务启动时自动执行"""
self.old_wsgi_app = wsgi_app
def __call__(self, environ, start_response):
"""每次有用户请求时执行"""
print('before')
obj = self.old_wsgi_app(environ, start_response)
print("after")
return obj
if __name__ == '__main__':
app.wsgi_app = Middleware(app.wsgi_app)
app.run()
标签:__,index,wsgi,flask,app,中间件,234.10,self,def 来源: https://www.cnblogs.com/liuzhanghao/p/16337538.html