我是flask的新手,面临一些问题,我需要根据输入请求在post函数中返回两件事。”200':说明:接受操作,“400”:说明:缺少必需的主体参数或类型不正确。 下面是我的代码
def post(self):
parser = reqparse.RequestParser(bundle_errors=True)
parser.add_argument('identifier', required=True)
parser.add_argument('fine', required=True)
# Parse the arguments into an object
args = parser.parse_args()
if args['identifier'] is None:
return {'message': 'Mandatory body parameter missing or have incorrect type', 'data': args}, 400
return {'message': 'operation accepted', 'data': args}, 200.
但当传入请求中没有标识符时,我无法返回400。我的语法有问题吗
在挖掘了一点之后,我发现应该删除required=True。如果我想得到我的回报值。否则,如果传入请求中缺少属性,Reqparser将引发错误
相关问题 更多 >
编程相关推荐