我正在使用ndb.Model.Search API具有以下字段类:
TextField : plain text
HtmlField : HTML formatted text
AtomField : a string which is treated as a single token
NumberField : a numeric value (either float or integer)
DateField : a date with no time component
GeoField : a locale based on latitude and longitude
Run Code Online (Sandbox Code Playgroud)
假设我有一个'tags'字段,它是一个列表字段:
tags = ndb.StringProperty(repeated=True)
Run Code Online (Sandbox Code Playgroud)
我该如何对待这个领域search.Document?
现在我把tags列表变成一个字符串:
t = '|'.join(tags)
Run Code Online (Sandbox Code Playgroud)
然后:
search.TextField(name=cls.TAGS, value=t)
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我有一个表单,在文本字段之间包含一个上传图片的元素.
我想将blob存储在blobstore中并ndb.Model使用我的model()引用它ndb.BlobKeyProperty().此链接中
显示的方法使用上传处理程序(),该处理程序从以这种方式创建的链接中调用:UploadHandler
upload_url = blobstore.create_upload_url('/upload')
Run Code Online (Sandbox Code Playgroud)
upload_url是为上传blob而创建的页面中的表单操作.但是,我的表单包含未在UploadHandlerpost方法中处理的其他字段.我找到的临时解决方案是为我的表单创建一个处理程序,该处理程序继承自我的BaseHandler和BlobstoreUploadHandler:
class EditProfile(blobstore_handlers.BlobstoreUploadHandler, BaseHandler)
def get(self):
params['upload_url'] = blobstore.create_upload_url('/upload_blob1')
... fields ...
def post(self):
upload_blob = self.get_uploads()
blob_key = upload_blob[0].key()
value_field1 = self.request.POST.get('field1')
value_field2 = self.request.POST.get('field2')
value_field3 = self.request.POST.get('field3')
...
Run Code Online (Sandbox Code Playgroud)
这个方法有效,除了我必须main.py为每个要上传blob的页面定义一个新的处理程序:
app = webapp2.WSGIApplication([ ('/upload_blob1', handlers.EditProfile),
('/upload_blob2', handlers.EditBlob2Handler),
('/serve/([^/]+)?', handlers.ServeHandler) ],
debug=os.environ['SERVER_SOFTWARE'].startswith('Dev'), config=webapp2_config)
Run Code Online (Sandbox Code Playgroud)
问题:如何使用UploadHandler从不同页面调用的单个上载处理程序(例如:)来执行上载blob任务?我知道对于经验丰富的GAE程序员来说这可能非常简单,但我还没有找到解决方案.