我有下面的类继承自flask-restplus.Resource。
class Patient(Resource):
""" Patient endpoint."""
@clinic_api_ns.route("/patient/add/")
def post(self):
# TODO: add a patient.
return {}
@clinc_api_ns.route("/patient/<string:name>")
def get(self, name):
# TODO: get a patient record
return {}
我想从上面实现2个端点,但是不起作用
它引发错误:
/site-packages/flask_restplus/api.py”,第287行,在_register_view中
resource_func = self.output(resource.as_view(endpoint,self,* resource_class_args,AttributeError:'function'对象没有属性'as_view'
最佳答案
您需要在类而不是函数上使用装饰器。
您的API将命中相同的端点“ /患者”,并且该方法将确定调用哪个函数。获取,发布,放置和删除。
如果需要不同的API端点,则将需要2个资源类,每个路径一个。
关于python - 如何从同一flask-restplus资源类获取和发布端点?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53919803/