本文整理汇总了Python中django.shortcuts.HttpResponse.content方法的典型用法代码示例。如果您正苦于以下问题:Python HttpResponse.content方法的具体用法?Python HttpResponse.content怎么用?Python HttpResponse.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.shortcuts.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.content方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resize
# 需要导入模块: from django.shortcuts import HttpResponse [as 别名]
# 或者: from django.shortcuts.HttpResponse import content [as 别名]
def resize(request, image_pk, width_str, height_str):
db_image = Image.objects.get(pk=image_pk)
response = HttpResponse(mimetype=db_image.content_type or 'image')
width, height = int(width_str), int(height_str)
if settings.ALLOW_CACHE_RESIZED_IMAGES:
resized_path = list(os.path.splitext(db_image.file.path))
resized_path.insert(1, '_%dx%d' % (width, height))
resized_path = ''.join(resized_path)
if os.path.exists(resized_path):
response.content = file(resized_path)
return response
image_type = db_image.content_type.replace('image/', '').upper()
image = PIL.Image.open(db_image.file).convert('RGBA')
resized = image.resize((int(width), int(height)), PIL.Image.ANTIALIAS)
if settings.ALLOW_CACHE_RESIZED_IMAGES:
resized.save(resized_path, image_type)
resized.save(response, image_type)
return response