title: Best way to write an image to a Django HttpResponse()
body: <p>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?</p>
  
  <pre><code>def secureImage(request,imagePath):
      response = HttpResponse(mimetype="image/png")
      img = Image.open(imagePath)
      img.save(response,'png')
      return response
  </code></pre>
  
  <p>(Image is imported from PIL.)</p>