Flask新手教程之- 在藍(lán)圖中使用請(qǐng)求鉤子、定義錯(cuò)誤處理
1. 藍(lán)圖支持請(qǐng)求鉤子,例如 before_request 和 after_request,可以在藍(lán)圖中定義這些鉤子來(lái)處理請(qǐng)求和響應(yīng)。
實(shí)例:
@auth.before_app_request
def before_request():
# 執(zhí)行在每個(gè)請(qǐng)求之前的操作
pass
@auth.after_app_request
def after_request(response):
# 執(zhí)行在每個(gè)請(qǐng)求之后的操作
return response
2. 在藍(lán)圖中定義錯(cuò)誤處理
實(shí)例:
@blog.errorhandler(404)
def page_not_found(error):
return 'Page not found', 404
本文來(lái)自博客園,作者:浪里小白龍qaq,轉(zhuǎn)載請(qǐng)注明原文鏈接:http://www.rzrgm.cn/xiao-bai-long/p/18551955

浙公網(wǎng)安備 33010602011771號(hào)