def gallery_thumb(request: HttpRequest, pk: int) -> HttpResponse:
try:
gallery = Gallery.objects.get(pk=pk)
except Gallery.DoesNotExist:
raise Http404("Gallery does not exist")
if not gallery.public and not request.user.is_authenticated:
raise Http404("Gallery is not public")
if 'HTTP_X_FORWARDED_HOST' in request.META:
response = HttpResponse()
response["Content-Type"] = "image/jpeg"
# response["Content-Disposition"] = 'attachment; filename*=UTF-8\'\'{0}'.format(
# archive.pretty_name)
response['X-Accel-Redirect'] = "/image/{0}".format(gallery.thumbnail.name)
return response
else:
return HttpResponseRedirect(gallery.thumbnail.url)
评论列表
文章目录