from flask import Flask, after_this_request

app = Flask(__name__)

@app.before_first_request
def before_first_request():
    print('这是请求钩子 before_first_request 注册的函数')

@app.before_request
def before_request():
    print('这是请求钩子 before_request 注册的函数')

@app.route('/index')
def index():
    print('hello flask')
    @after_this_request
    def after_this_request_func(response):
        print('这是请求钩子 after_this_request_func 注册的函数')
        return response
    return 'hello flask'

@app.after_request
def after_request(response):
    print('这是请求钩子 after_request 注册的函数')
    return response

@app.teardown_request
def teardown_request(error):
    print('这是请求钩子 teardown_request 注册的函数')

if __name__ == '__main__':
    app.run()