在校验请求参数的时候,type 参数类型可以设置为正则匹配,邮箱匹配,url匹配等在inputs模块有补充。
flask_restful.inputs 常用的一些数据校验
写一个注册视图,对请求入参校验
class RegisterView(Resource):
def post(self):
# 创建解析器对象
parser = reqparse.RequestParser()
# 需要验证的参数
parser.add_argument('username', type=str, required=True, trim=True, help='用户名不合法' )
parser.add_argument('password', type=str, required=True, help='密码不合法')
parser.add_argument('age', type=int, help='年龄不合法')
parser.add_argument('sex', type=str, choices=['男', '女'], help='性别不合法')
parser.a