在装饰前执行before_request
装饰后执行after_request
根据代码体验一下吧,看看他们的先后顺序
from flask import Flask,render_template,redirect app = Flask(__name__) @app.before_request def xx1(): print("前1") @app.before_request def xx2(): print("前2") @app.after_request def xx1(response): print("后1") return response @app.after_request def xx2(response): print("后2") return response @app.route(‘/x1‘,methods=["GET","POST"]) def x1(): print("视图函数x1") return "视图函数x1" @app.route(‘/x2‘,methods=["GET","POST"]) def x2(): print("视图函数x2") return "视图函数x2" if __name__ == ‘__main__‘: app.run()
原文地址:https://www.cnblogs.com/1996-11-01-614lb/p/8975818.html
时间: 2024-10-31 03:12:24