Filipe wrote:
Ian Holsman wrote:
  
im = Image.open('%s/blah.jpg' % settings.MEDIA_ROOT )
     resp = HttpResponse( mimetype="image/jpeg" )
     im.save( resp, 'JPEG' )
     return resp
?
    

yeah, precisely! thanks.
although it works perfectly there's something I don't quite understand
(i'm still a newbie to python). Isn't save() supposed to receive a
filename as the first argument? We're passing it a HttpResponse...
  
>From the documentation for HttpResponse (http://www.djangoproject.com/documentation/request_response/):

But if you want to add content incrementally, you can use response as a file-like object:

>>> response = HttpResponse()
>>> response.write("<p>Here's the text of the Web page.</p>")
>>> response.write("<p>Here's another paragraph.</p>")

This is an example of Python's "duck typing".  Because HttpResponse implements the same methods as a file, it can be used in any place that a file can be used.  PIL's save() method expects a file, but all it does is call write() (and maybe some other file methods).  HttpResponse implements those methods with appropriate semantics, so it's known as "file-like", and can be used as a file can be used.

--Ned.
-- 
Ned Batchelder, http://nedbatchelder.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---




Reply via email to