繁体   English   中英

flask restful api 中的 add_resource() 中的端点参数有什么用?

[英]what is the use of endpoint parameter in add_resource() in flask restful api?

我写了两个api,一个是创建设备(POST),另一个是列出所有设备(GET)。

in app.py
---------
# Get the List of the devices
api.add_resource(DeviceDetail, "/v1/t/device/")
# Create new Devices
api.add_resource(DeviceDetail, "/v1/t/device/create")

in controller/device.py
class DeviceDetail(Resource):
      def get(): 
         #some code to list out all the device and return the response
      def post():
         #some code to insert the record to db and return the response

AssertionError:查看 function 映射正在覆盖现有端点 function:设备详细信息。

如果我将端点参数传递给 add_resource() 那么我没有收到任何错误。

# Get the List of the devices
api.add_resource(DeviceDetail, "/v1/t/device/",endpoint='get_the_list_of_deives')
# Create new Devices
api.add_resource(DeviceDetail, "/v1/t/device/create",endpoint='create_the_deivce')

所以我很困惑,它在这里做了什么。

Flask 文档说:

端点(str)–端点名称(默认为资源。名称.lower()可用于在字段中引用此路由。Url字段

如果您不提供端点 Flask 将为您创建默认端点,并且您的错误清楚地说明了问题所在。 View function mapping is overwriting an existing endpoint function: devicedetail

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM