我正在尝试实现一项服务,该服务检查登录用户是否在数据存储上,如果是,则返回True,否则返回False。 这是我正在使用的代码:
import endpoints
from google.appengine.ext import ndb
from protorpc import remote
from protorpc import messages
from endpoints_proto_datastore.ndb import EndpointsModel
from google.appengine.api import users
class AuthRes(messages.Message):
message = messages.StringField(1)
class UserModel(EndpointsModel):
user = ndb.UserProperty()
@endpoints.api(name='myapi', version='v1', description='My Little API')
class MyApi(remote.Service):
@UserModel.method(path='myuser', http_method='GET', name='myuser.check')
def UserCheck(self, cls):
user = users.get_current_user()
if user:
myuser = cls.query().filter(cls.user.user_id() == user.user_id()).get()
if not myuser:
return AuthRes(message="False")
else:
return AuthRes(message="True")
else:
return AuthRes(message="False")
application = endpoints.api_server([MyApi], restricted=False)
我总是得到'AuthRes' object has no attribute 'ToMessage'
答案 0 :(得分:0)
我相信而不是:
@UserModel.method(path='myuser', http_method='GET', name='myuser.check')
你想要这个:
from protorpc import message_types # add at the top
@endpoints.method(message_types.VoidMessage, AuthRes, path='myuser', http_method='GET', name='myuser.check')