在flask-restplus中的GET端点中显示参数

时间:2019-01-09 01:49:30

标签: flask-restful

使用Flask-RESTPlusAPI并执行GET时,看起来像这样

curl -X GET“ http://localhost:5000/r1” -H“ accept:application / json”

我想在下拉列表中填充“ r1”,“ r2”,“ r3”等,类似于“ / hello”

from flask import Flask
from flask_restplus import Resource, Api, reqparse

parser = reqparse.RequestParser()
parser.add_argument('rate', type=str,choices=['r1','r2','r3'],required=True)

app = Flask(__name__)
api = Api(app)

@api.route('/hello')
class HelloWorld(Resource):

    @api.expect(parser)
    def get(self):
        return {'hello': 'world'}

@api.route('/<test>')
@api.param('test', 'Some description')
class TestResource(Resource):
    def get(self, test):
        pass

if __name__ == '__main__':
    app.run(debug=True)

0 个答案:

没有答案