flask-RequestParser参数解析处理

flask中flask_restful库中reqparse.RequestParser可以对表单数据进行验证。

from flask_restful import reqparse
root_parse = reqparse.RequestParser() #设置一个参数检验解析器
root_parse.add_argument("targe_name", type="str", location="json", required=True, nullable=False, help="targe_name内容为空")
root_parse.add_argument(...)
root_args = root_parse.parse_args()
root_parse = reqparse.RequestParser() #设置一个参数检验解析器
root_parse.add_argument:为roota_parse添加一个检验参数
  • "targe_name":需要检验的参数名称
  • type:检验的参数类型
  • location:检验的参数来源
  • required:是否必须检验
  • nullable:检验结果是否可以为空
  • help:检验不通过时返回的信息

root_args = root_parse_args() #解析结果

posted @ 2021-10-15 16:51  一笔一划82  阅读(773)  评论(0)    收藏  举报