Serve a dynamically generated image with Django

I assume you’re using PIL (Python Imaging Library). You need to replace your last line with (for example, if you want to serve a PNG image):

response = HttpResponse(mimetype="image/png")
img.save(response, "PNG")
return response

See here for more information.

Leave a Comment