我正尝试编写一个新的python rest api,如下所示,
from flask import Flask
from com.app.Controller import Event1LogicClass
from com.app.Controller import Event2LogicClass
from flask import Flask
from flask_restful import Api
com.app:
app = Flask(__name__)
apiRest = Api(app)
apiRest.add_resource(Event1LogicClass, '/Count/<string:days>')
apiRest.add_resource(Event2LogicClass,'/Count/<string:days>/<string:givenDate>')
if __name__ == '__main__':
app.run(debug = True)
com.app.Controller:
class Event1LogicClass(Resource)
def get(self, days):
return "Event1LogicClass"
com.app.Controller:
class Event2LogicClass(Resource)
def get(self, days, givenDate):
return "Event2LogicClass"
当我选择MainClass作为主类并运行时,它给出
resource_func = self.output(resource.as_view(endpoint, *resource_class_args,
AttributeError: module 'com.app.Controller.Event1LogicClass' has no attribute 'as_view'
我想在MainClass中添加多个rest调用,并根据apiRest.add_resource中的类调用api功能。
我在哪里做错了?