如何在flask_restplus中使用()返回具有多个封送处理的响应?

如何在flask_restplus中使用()返回具有多个封送处理的响应?,flask,flask-restplus,Flask,Flask Restplus,下面是PUT动词的flask\u restplus响应调用 @api.doc('update a franchise by id') @api.expect(create_item_fields, validate=True) @api.marshal_with(success_fields) def put(self, fid): franchise = FranchiseModel.query.filter_by(id=fid).first()

下面是PUT动词的
flask\u restplus
响应调用

@api.doc('update a franchise by id')
    @api.expect(create_item_fields, validate=True)
    @api.marshal_with(success_fields)
    def put(self, fid):
        franchise = FranchiseModel.query.filter_by(id=fid).first()
        if franchise:
            is_success, result = FranchiseModel.update_franchise(
                franchise, api.payload)
            if is_success:
                return {'success': True, 'message': 'Franchise has been updated', 'data': result}, 200
            else:
                raise CouldNotUpdateFranchise(str(result))

@api.errorhandler(CouldNotUpdateFranchise)
    @api.marshal_with(error_fields)
    def return_error(error):
        return {'success': False, 'message': str(error)}, 400

我正在使用
@api.errorhandler
,但我不知道如何使用
marshall\u和
编辑返回多个响应格式:Ok旧答案只是将其作为一个有效的响应以虚张声势列出

但通过这篇文章,我仍然得到了解决方案:

from flask_restplus import marshal
# I call API 'foo' and my Namespace 'bar'
another = foo.model('For 200', {'Another': fields.Integer()})
success = foo.model('For 201', {'Success': fields.Integer()})

@bar.route('/test/<int:id>')
class Test(Resource):
    @bar.response(model=another, code=200)
    @bar.response(model=success, code=201)
    def get(self, id):
        if id == 200:
             return marshal({'Another': 200}, another), 200
        elif id == 201:
             return marshal({'Success': 201}, success), 201
来自flask\u restplus导入封送
#我调用API“foo”和名称空间“bar”
另一个=foo.model('For 200',{'other':fields.Integer()})
success=foo.model('For 201',{'success':fields.Integer()})
@条形布线(“/test/”)
课堂测试(资源):
@条形响应(型号=另一个,代码=200)
@条形图响应(模型=成功,代码=201)
def get(自我,id):
如果id==200:
返回封送处理({'otheran':200},otheran),200
elif id==201:
返回封送处理({'Success':201},Success),201

我希望你明白我想说的话。。。现在有点晚了。。。