【问题标题】:Webfaction Django 1.4.1: easy_thumbnails 3.0b – "Couldn't get the thumbnail" errorWebfaction Django 1.4.1:easy_thumbnails 3.0b –“无法获取缩略图”错误
【发布时间】:2012-09-06 15:05:07
【问题描述】:

我使用easy_thumbnails,它在开发机器上运行良好,但在生产中,当我使用{% thumbnail photo.image 300x170 %} templatetag 时出现如下所示的错误。

虽然可以直接浏览http://sitename.com/media/uploads/2012/09/13/microsoft1.jpeg`。 媒体设置也正确,上传的内容也放在了正确的位置,缺少什么,那么可能出了什么问题?

File "/home/imanhodjaev/lib/python2.7/django/template/base.py" in render
  823. bit = self.render_node(node, context)
File "/home/imanhodjaev/lib/python2.7/django/template/debug.py" in render_node
  74. return node.render(context)
File "/home/imanhodjaev/lib/python2.7/easy_thumbnails/templatetags/thumbnail.py" in render
  99. (source, e))
Exception Type: TemplateSyntaxError at /petition/microsoft-myi-hotim-kyirgyizskij-rasklad-klaviatur/update-picture
Exception Value: Couldn't get the thumbnail uploads/2012/09/13/microsoft1.jpeg: The source file does not appear to be an image

型号

使用来自easy_thumbnailsThumbnailerImageField

class Petition(models.Model):
    title = models.CharField(max_length=512)
    slug = models.SlugField(max_length=512, editable=False, blank=True)
    description = models.TextField()
    petition_text = models.TextField(blank=True, null=True)
    petition_picture = ThumbnailerImageField(upload_to=get_upload_path, blank=True)

更新

我从 Django 的管理 shell 进行了调查,get_thumbnailer 函数工作正常

>>> thumb_url = get_thumbnailer(pet.petition_picture)
>>> thumb_url
<ThumbnailerImageFieldFile: uploads/2012/09/13/microsoft1.jpeg>
>>> thumb_url.url
'/m/uploads/2012/09/13/microsoft1.jpeg'

当我调用 get thumbnail 方法时它失败了

>>> thumb_url = get_thumbnailer(pet.petition_picture).get_thumbnail(options)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/imanhodjaev/lib/python2.7/easy_thumbnails/files.py", line 380, in get_thumbnail
    thumbnail = self.generate_thumbnail(thumbnail_options)
  File "/home/imanhodjaev/lib/python2.7/easy_thumbnails/files.py", line 290, in generate_thumbnail
    "The source file does not appear to be an image")
InvalidImageFormatError: The source file does not appear to be an image

【问题讨论】:

  • 尝试使用其他图片会产生什么结果?
  • 其他图片的结果相同
  • 您可以通过在 django shell 中编码获得更多信息:github.com/SmileyChris/…
  • 它给出了InvalidImageFormatError,尽管它可以在开发机器上使用相同的图像
  • 这个应用依赖于PIL。你也需要检查一下。

标签: python django thumbnails webfaction


【解决方案1】:

问题是因为默认情况下,我的 Webfaction 实例上的 pip install PILlibjpeg 链接,pip install PIllow 也链接到 http://community.webfaction.com/questions/7340/how-to-install-pil-with-truetype-support 上的文章

【讨论】:

  • 只是为了确认这一点:我所需要的只是 Webfaction 上的基本 sorl 缩略图。关键是安装 Pillow 而不是 PIL,它开箱即用。
猜你喜欢
  • 1970-01-01
  • 2012-05-05
  • 1970-01-01
  • 1970-01-01
  • 2020-03-26
  • 1970-01-01
  • 2022-08-22
  • 2011-08-10
  • 1970-01-01
相关资源
最近更新 更多