这个简单的应用程序有两个teardown_request
处理程序,我希望每个请求都调用它们,无论视图实现中发生什么,根据文档
import flask
import werkzeug.exceptions
app = flask.Flask(__name__)
@app.teardown_request
def teardown1(response):
print "Teardown 1"
return response
@app.teardown_request
def teardown2(response):
print "Teardown 2"
return response
@app.route("/")
def index():
return "chunky bacon"
@app.route("/httpexception")
def httpexception():
raise werkzeug.exceptions.BadRequest("no bacon?")
@app.route("/exception")
def exception():
raise Exception("bacoff")
if __name__ == "__main__":
app.run(port=5000)
但是,当我运行它并依次向三个视图发出请求时,我得到以下输出:
拆解 2 拆解 1 127.0.0.1 - - [2011 年 11 月 15 日 18:53:16] “GET / HTTP/1.1” 200 - 拆解 2 拆解 1 127.0.0.1 - - [2011 年 11 月 15 日 18:53:27] “GET /httpexception HTTP/1.1”400 - 拆解 2 127.0.0.1 - - [2011 年 11 月 15 日 18:53:33] “GET /异常 HTTP/1.1”500 -
当最后一个视图引发teardown_request
非派生异常时,仅调用其中一个函数。werkzeug.exceptions.HTTPException
任何想法为什么,或者这是烧瓶中的错误?