【发布时间】: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_thumbnails的ThumbnailerImageField
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