gpt4 book ai didi

python - 等效于 Python 中的 @Named API 参数

转载 作者:行者123 更新时间:2023-11-28 21:24:45 26 4
gpt4 key购买 nike

有没有办法在 Python 中使用命名方法参数 - 对应于这个 Java 示例:

@ApiMethod(
name = "foos.remove",
path = "foos/{id}",
httpMethod = HttpMethod.DELETE,
)
public void removeFoo(@Named("id") String id) {
}

在我的 Python 版本中,如果我将 @endpoints.method 路径设置为 foos/{id},URL 会正确匹配,但我如何访问参数?

最佳答案

没有严格的等价,但是如果{id}在你的路径中,那么protorpc中一定有一个名为id的字段> 您在方法中用于请求类的消息类。

例如:

from google.appengine.ext import endpoints
from protorpc import messages
from protorpc import remote

class MyMessageClass(messages.Message):
id = messages.StringField(1) # Or any other field type

@endpoints.api(...)
class MyApi(remote.Service):
@endpoints.method(MyMessageClass, SomeResponseClass,
..., path='foos/{id}')
def my_method(self, request):
...

关于python - 等效于 Python 中的 @Named API 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15466517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com