我有一个卡片类。
class Card(db.Model):
name = db.StringProperty(required = True)
image = '''insert property here'''
description = db.TextProperty(required = True)
submitted = db.DateTimeProperty(auto_now_add = True)
如何将图像添加到课程中?
我有一个卡片类。
class Card(db.Model):
name = db.StringProperty(required = True)
image = '''insert property here'''
description = db.TextProperty(required = True)
submitted = db.DateTimeProperty(auto_now_add = True)
如何将图像添加到课程中?
对于二进制数据,您可以使用 a (请参阅此处BlobProperty
的文档),使您的代码:
class Card(db.Model):
name = db.StringProperty(required = True)
image = db.BlobProperty()
description = db.TextProperty(required = True)
submitted = db.DateTimeProperty(auto_now_add = True)
然后,您可以按如下方式分配给您的属性(假设您的用户表单中的图像参数是image
;如果不使用表单,您可以像对待其他二进制数据一样对待图像):
my_card = Card()
# Other properties defined here...
my_image = self.request.get('image')
card.image = db.Blob(my_image)
my_card.put()