APIFlask 0.5.0 发布:添加类视图支持

这个版本主要添加了类视图支持(class-based views):

# ...
# use the "route" decorator to decorate the view class
@app.route('/')
class Hello(MethodView):

    # use HTTP method name as class method name
    def get(self):
        return {'message': 'Hello!'}


@app.route('/pets/<int:pet_id>')
class Pet(MethodView):

    @output(PetOutSchema)
    def get(self, pet_id):
        # ...

    @input(PetInSchema)
    @output(PetOutSchema)
    def put(self, pet_id, data):
        # ...

完整的示例程序可以在源码仓库找到。更多变动记录见 changelog

1 个赞