Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 如何使用端点原型数据存储返回模型以外的内容_Python 2.7_Google Cloud Endpoints_Endpoints Proto Datastore - Fatal编程技术网

Python 2.7 如何使用端点原型数据存储返回模型以外的内容

Python 2.7 如何使用端点原型数据存储返回模型以外的内容,python-2.7,google-cloud-endpoints,endpoints-proto-datastore,Python 2.7,Google Cloud Endpoints,Endpoints Proto Datastore,我正在通过谷歌云端点和端点原型数据存储库编写一个API 这是我的模型: class Domain(EndpointsModel): _message_fields_schema = ('id', 'name', 'enabled', 'adminEmails') name = ndb.StringProperty(required=True) enabled = ndb.BooleanProperty(required=True) adminEmails = nd

我正在通过谷歌云端点和端点原型数据存储库编写一个API

这是我的模型:

class Domain(EndpointsModel):
    _message_fields_schema = ('id', 'name', 'enabled', 'adminEmails')
    name = ndb.StringProperty(required=True)
    enabled = ndb.BooleanProperty(required=True)
    adminEmails = ndb.StringProperty(repeated=True)
这是我的删除方法:

@Domain.method(request_fields=('id',), path='domains/{id}', http_method='DELETE', name='domain.delete')
def delete_domain(self, domain):
    if not domain.from_datastore:
        raise endpoints.NotFoundException('Domain not found.')
    domain._key.delete()
    return domain

我可以返回模型本身以外的其他内容吗?如何返回特定的HTTP状态码或类似于VoidMessage的内容?

您可以在装饰器中定义一个
response\u message
参数(与更常用的
response\u字段
参数相反),并将其设置为
VoidMessage
。然后从方法而不是模型返回一条
VoidMessage

from protorpc import message_types

(...)

@Domain.method(request_fields=('id',),
               response_message=message_types.VoidMessage,
               path='domains/{id}',
               http_method='DELETE',
               name='domain.delete')
def delete_domain(self, domain):

    (...)

    return message_types.VoidMessage()
当然,您也可以通过这种方式返回任何其他protorpc消息。
据我所知,无法定义要返回的HTTP状态代码。

您可以在装饰器中定义一个response\u message参数(与更常用的response\u字段参数相反),并将其设置为VoidMessage。然后从方法而不是模型返回一条
VoidMessage

from protorpc import message_types

(...)

@Domain.method(request_fields=('id',),
               response_message=message_types.VoidMessage,
               path='domains/{id}',
               http_method='DELETE',
               name='domain.delete')
def delete_domain(self, domain):

    (...)

    return message_types.VoidMessage()
当然,您也可以通过这种方式返回任何其他protorpc消息。
据我所知,无法定义要返回的HTTP状态代码。

这是正确的。状态代码由谓词和有效负载的组合确定,或者如果出现错误,则由错误的名称确定。这是正确的。状态代码由谓词和有效负载的组合确定,或者如果出现错误,则由错误名称确定。