2

Pythonで名前付きメソッドパラメータを使用する方法はありますか?このJavaの例に対応しています:

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

私のPythonバージョンでは、URLへの@endpoints.methodパスを設定するfoos/{id}と正しく一致しますが、パラメーターにアクセスするにはどうすればよいですか?

4

1 に答える 1

6

厳密に同等のものはありませんが、がパスにある場合は、メソッドのリクエストクラスに使用するメッセージクラスに呼び出さ{id}れるフィールドが必要です。idprotorpc

例えば:

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):
    ...
于 2013-03-18T03:57:28.737 に答える