On Tue, 2006-09-26 at 12:42 +0100, Tom Smith wrote:
> Nearly there.... with this code...
>
> from PIL import Image,ImageFile
> def get_image(src):
> import urllib
>
> fp = urllib.urlopen(src, "rb")
> p = ImageFile.Parser()
>
> while 1:
> s = fp.read(1024)
> print ".",
> if not s:
> break
> p.feed(s)
>
> im = p.close()
> im.thumbnail((128,128),Image.ANTIALIAS)
> im.save("/Users/tomsmith/Desktop/" + src)
>
> for product in Product.objects.all( ).order_by('-id')[:10]:
> print product.id
> print product.img
> print product.url
> get_image(product.img)
>
> ... but I think I get a "redirect" header if I use urllib2... and
> urllib seems to just wait and wait....
I'm not sure if this is what is going wrong in your code, but one
potential problem here is that you are mixing up filesystem paths with
URLs. The value of product.img will be the path in the filesystem where
the image is stored. If you are trying to retrieve this image using your
HTTP server, you need to know the URL for accessing the file, which may
or may not be related to the filesystem path.
To get the URL for an image field (or any FileField derivative), use the
get_FOO_url() method -- where FOO is the name of your field. In your
case, product.get_img_url() is the URL to the image.
This, and some other special methods for accessing this sort of
information, is documented at
http://www.djangoproject.com/documentation/db_api/#get-foo-url
Hope that helps somewhat.
Cheers,
Malcolm
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---