我使用django-imagekit处理上传图片,我遇到了以下错误:
AttributeError at /car/7/
'cStringIO.StringO' object has no attribute 'fileno'
Request Method: GET
Request URL: http://luxingnan.azurewebsites.net/car/7/
Django Version: 1.8
Exception Type: AttributeError
Exception Value:
'cStringIO.StringO' object has no attribute 'fileno'
Exception Location: D:\home\site\wwwroot\env\Lib\site-packages\pilkit\utils.py in
__enter__, line 248
Python Executable: D:\Python27\python.exe
Python Version: 2.7.8
Python Path:
[u'D:\\home\\site\\wwwroot\\env\\Lib\\site-packages', '.', 'D:\\Windows\\SYSTEM32\\python27.zip', 'D:\\Python27\\DLLs', 'D:\\Python27\\lib', 'D:\\Python27\\lib\\plat-win', 'D:\\Python27\\lib\\lib-tk', 'D:\\Python27', 'D:\\Python27\\lib\\site-packages', 'D:\\home\\site\\wwwroot']
Server time: Thu, 16 Apr 2015 12:28:26 +0000
下面是我的代码:
# models.py
class Carpic(models.Model):
picture = models.ImageField('pic',upload_to='car-pictures')
picture_slide = ImageSpecField(source='picture',
processors=[ResizeToFill(762, 456)],
format='JPEG',
options={'quality': 60}
)
# template.html
{% for pic in pictures %}
<li><img src="{{pic.picture_slide.url}}"/></li>
{% endfor %}
有人可以告诉我该怎么办?感谢
答案 0 :(得分:1)
刚才有机会看到这个(和your GH Issue)。我会在这里包括我的回答,因为这样做似乎是正确的事情(:
所以看起来这是Azure的一个怪癖,但我们绝对可以在PILKit中修复它。
PILKit a utility用于平息PIL的一些噪音。它的方式是temporarily replacing stderr(使用其文件描述符)。显然在Azure上,stderr是StringIO的一个实例(没有文件描述符)。对于那种情况,我们只需要为实用程序添加一个保护(就像when dev/null isn't writeable的那个)。这是一个很小的变化,但我现在很忙。 PR非常感谢!
因此,换句话说,它不是FileWrapper的问题(如评论中所建议的),而是Azure的假stderr和PILKit的quiet
实用程序的组合。