Error uploading images using Django, Google app engine
I'm building a web app using Django for Google App Engine, with the djangoappengine library. I'm stuck on getting image uploads working via the admin interface. My models.py
is:
class Bio(models.Model):
name = models.CharField(max_length=25)
开发者_开发百科 about = models.TextField()
email = models.TextField()
pic = models.ImageField(upload_to="img/bios/", null=True, blank=True)
When I try to upload an image in the default admin interface, both locally and on the appspot website, I get: "ImportError: No module named Image"
But! -- when I run manage.py shell
I am able to successfully import Image
and from PIL import Image
, so I'm not sure what I'm missing here. Any ideas?
http://www.allbuttonspressed.com/projects/djangoappengine#field-types says that ImageField isn't supported.
Try uploading to blobstore (see http://code.google.com/appengine/docs/python/blobstore/overview.html). That basically uses an intervening handler that stores the image, handing back a blob key instead of a file to your destination handler.
Django's ImageField uses PIL to check if the uploaded file is actually an image. The problem is, PIL was not available on AppEngine server initially, so you had to use AppEngine's Images API instead.
While googling around, I found this implementation of ImageField widget for AppEngine, that uses google.appengine.api.images instead of PIL.
Seems like AppEngine supports PIL on Python 2.7 now though. So if you're developping a Python 2.7 app on AppEngine, all you need is to turn the support of PIL on in app.yaml
精彩评论