【发布时间】:2014-12-24 14:41:29
【问题描述】:
我有一个 django 应用程序,我想公开模型图像,这样当我请求 /image/school_id/400 时,它会返回 ID 为 school_id 的学校图像,并将其裁剪并调整为 400x400 像素的框。这是我尝试过的
@api_view(['GET', 'POST'])
def image_view(request, school_id, size):
image = School.objects.get(school__pk=school_id).image
resized_img = image #Handle resizing here
return Response(resized_img, content_type='*/*')
我得到的只是一个错误'utf8' codec can't decode byte 0xff in position 0: invalid start byte
我如何返回图像? 我正在使用 Django-rest-framework http://www.django-rest-framework.org/api-guide/renderers#advanced-renderer-usage
【问题讨论】:
标签: python django rest django-models django-rest-framework