标签:tar wsgi env flask 有用 sel init cal __call__
from flask import Flask
app = Flask(__name__)
@app.route(‘/‘)
def index():
return ‘Hello World!‘
class Md(object):
def __init__(self,old_wsgi_app):
self.old_wsgi_app = old_wsgi_app
def __call__(self, environ, start_response):
print(‘开始之前‘)
# 。。。一些自定义操作
ret = self.old_wsgi_app(environ, start_response)
# 。。。一些自定义操作
print(‘结束之后‘)
return ret
if __name__ == ‘__main__‘:
# 封装旧的app.wsgi_app,这是app.run()的原理,看源码。会调用__call__方法
app.wsgi_app = Md(app.wsgi_app)
app.run()
标签:tar wsgi env flask 有用 sel init cal __call__
原文地址:https://www.cnblogs.com/allen2333/p/9017756.html