Search code examples
python-3.xflask-restplus

KeyError: 'view_class' in Flask-restplus. Routing not working


According to the official documentation page, routes are initiated this way. I have done the same thing with the code below but for some reason, I get a KeyError: 'view_class':

from flask import Flask
from flask_restplus import Resource, Api

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


@api.route('/')
@api.route('/api')
class Root(Resource):
    def get(self):
        return {'message': 'it works'}, 200


@api.route('/test')
class Test(Resource):
    def post(self):
        pass


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

What am I doing wrong?


Solution

  • To fix your code, change the Root class name to anything else. I've verified this fixes your problem. Unfortunately I don't see how that specific class name causes an issue based on reading the Flask-RESTPlus source. Sounds like you may have found a bug.