简体   繁体   English

使用Django,Google应用引擎上传图片时出错

[英]Error uploading images using Django, Google app engine

I'm building a web app using Django for Google App Engine, with the djangoappengine library. 我正在使用Django for Google App Engine和djangoappengine库构建一个Web应用程序。 I'm stuck on getting image uploads working via the admin interface. 我坚持通过管理界面获取图片上传工作。 My models.py is: 我的models.py是:

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" 当我尝试在本地和appspot网站上的默认管理界面中上传图像时,我得到:“ImportError:没有名为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. - 当我运行manage.py shell我能够成功import Imagefrom PIL import Image ,所以我不确定我在这里缺少什么。 Any ideas? 有任何想法吗?

http://www.allbuttonspressed.com/projects/djangoappengine#field-types says that ImageField isn't supported. http://www.allbuttonspressed.com/projects/djangoappengine#field-types表示不支持ImageField。

Try uploading to blobstore (see http://code.google.com/appengine/docs/python/blobstore/overview.html ). 尝试上传到blobstore(请参阅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. 这基本上使用了一个存储图像的介入处理程序,将blob键而不是文件传递给目标处理程序。

Django's ImageField uses PIL to check if the uploaded file is actually an image. Django的ImageField使用PIL检查上传的文件是否实际上是图像。 The problem is, PIL was not available on AppEngine server initially, so you had to use AppEngine's Images API instead. 问题是,PIL最初在AppEngine服务器上不可用,因此您必须使用AppEngine的Images API

While googling around, I found this implementation of ImageField widget for AppEngine, that uses google.appengine.api.images instead of PIL. 虽然谷歌搜索的时候,我发现这个实现 ImageField的小部件的应用服务引擎,它使用的不是PIL google.appengine.api.images。

Seems like AppEngine supports PIL on Python 2.7 now though. 看起来像AppEngine现在支持Python 2.7上的PIL。 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 因此,如果您正在AppEngine上开发Python 2.7应用程序,您只需在app.yaml中打开PIL的支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM