【发布时间】:2014-10-22 09:48:12
【问题描述】:
我有一个 google-cloud-endpoints,在文档中,我没有找到如何编写 PATCH 方法。
我的要求:
curl -XPATCH localhost:8080/_ah/api/hellogreeting/1 -d '{"message": "Hi"}'
我的方法处理程序如下所示:
from models import Greeting
from messages import GreetingMessage
@endpoints.method(ID_RESOURCE, Greeting,`
path='hellogreeting/{id}', http_method='PATCH',
name='greetings.patch')
def greetings_patch(self, request):
request.message, request.username
greeting = Greeting.get_by_id(request.id)
greeting.message = request.message # It's ok, cuz message exists in request
greeting.username = request.username # request.username is None. Writing the IF conditions in each string(checking on empty), I think it not beatifully.
greeting.put()
return GreetingMessage(message=greeting.message, username=greeting.username)
所以,现在Greeting.username 中的字段将为无。这是错误的。
在每个字符串中写入 IF 条件(检查是否为空),我认为它并不完美。
那么,模型部分更新的最佳方式是什么?
【问题讨论】:
标签: google-app-engine python-2.7 google-cloud-endpoints