本文整理汇总了Python中models.Image.get_by_key_name_or_id方法的典型用法代码示例。如果您正苦于以下问题:Python Image.get_by_key_name_or_id方法的具体用法?Python Image.get_by_key_name_or_id怎么用?Python Image.get_by_key_name_or_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Image
的用法示例。
在下文中一共展示了Image.get_by_key_name_or_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import get_by_key_name_or_id [as 别名]
def post(self):
"Delete a given image"
key = self.request.get("key")
if key:
image = Image.get_by_key_name_or_id(key)
image.delete()
# whatever happens rediect back to the main admin view
self.redirect('/')
示例2: get
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import get_by_key_name_or_id [as 别名]
def get(self):
# key is provided in the query string
img = self.request.get("id")
try:
# it might be an invalid key so we better check
image = Image.get_by_key_name_or_id(img)
except db.BadKeyError:
# if it is then return a 404
self.error(404)
return
if image and image.image:
# we have an image so prepare the response
# with the relevant headers
self.response.headers['Content-Type'] = "image/png"
# and then write our the image data direct to the response
self.response.out.write(eval("image.%s" % self.property))
else:
# we should probably return an image with the correct header
# here instead of the default html 404
self.error(404)