类型
app.before_first_request
视图函数无参数
无返回
app.befor_request
视图函数无参数
无返回
app.after_request(无异常时,执行)
视图函数有参数,响应对象
返回响应
app.teardown_request(有无异常,都执行)
视图函数有参数,响应对象
返回响应
示例
#-*-coding:utf-8 -*-
from flask import Flask,request,url_for
from flask_script import Manager
app=Flask(__name__)
manager=Manager(app) #管理app应用的对象
@app.route("/")
def index():
return "hi"
@app.teardown_request
def ha(response):
path=request.path
if path == url_for("index"):
print("index")
return response
manager.run()