Best way to write an image to a Django HttpResponse()
Posted
by k-g-f
on Stack Overflow
See other posts from Stack Overflow
or by k-g-f
Published on 2010-06-09T04:50:33Z
Indexed on
2010/06/09
4:52 UTC
Read the original article
Hit count: 199
images
|django-views
I need to serve images securely to validated users only (i.e. they can't be served as static files). I currently have the following Python view in my Django project, but it seems inefficient. Any ideas for a better way?
def secureImage(request,imagePath):
response = HttpResponse(mimetype="image/png")
img = Image.open(imagePath)
img.save(response,'png')
return response
(Image is imported from PIL.)
© Stack Overflow or respective owner