我正在使用Django REST框架提供图像服务,但不幸的是它下载而不是显示。我猜我需要设置头部Content-Disposition = 'inline'
。我应该如何在View
或Renderer
中设置?
class ImageRenderer(renderers.BaseRenderer):
media_type = 'image/*'
format = '*'
charset = None
render_style = 'binary'
def render(self, data, media_type=None, renderer_context=None):
return data
class ImageView(APIView):
renderer_classes = (ImageRenderer, )
def get(self, request, format=None):
image=MyImage.objects.get(id=1)
image_file = image.thumbnail_png.file
return Response(image)