请求钩子是通过装饰器的形式实现的,支持以下四种:
1,before_first_request 在处理第一个请求前运行
2,before_request:在每次请求前运行
3,after_request:如果没有未处理的异常抛出,在每次请求后运行
4,teardown_request:即使有未处理的异常抛出,在每次请求后运行

 

# 请求钩子

1. @api.after_request
2. def after_request(response):
3. """设置默认的响应报文格式为 application/json"""
4. # 如果响应报文 response 的 Content-Type 是以 text 开头,则将其改为
5. # 默认的 json 类型
6. if response.headers.get("Content-Type").startswith("text"):
7. response.headers["Content-Type"] = "application/json"
8. return respon

 

相关文章:

  • 2021-09-24
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2022-02-10
  • 2022-12-23
猜你喜欢
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2021-08-03
  • 2021-05-28
  • 2021-10-02
相关资源
相似解决方案