0

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?

Mysterio
  • 2,878
  • 2
  • 15
  • 21

2 Answers2

2

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.

dmulter
  • 2,608
  • 3
  • 15
  • 24
1

If you want to have multiple routes to the same resources then you can do as in this example: http://flask.pocoo.org/snippets/57/.

Carl Onsjö
  • 151
  • 1
  • 5
  • I just deleted `@api.route('/api')` and the error still persists so it can't be that causing the error – Mysterio Apr 26 '19 at 12:00