Reputation: 3427
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?
Upvotes: 0
Views: 970
Reputation: 2748
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.
Upvotes: 2
Reputation: 196
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/.
Upvotes: 1