django - ZeroDivisionError when using thumbnail low-level API
Question: I implemented thumbnails for images that are displayed in an inline form, by
creating my custom form ([like
this](http://blog.glaucocustodio.com/2014/04/08/display-thumbnails-in-django-
admin-with-sorl-thumbnail/)).

However, in one case (that I noticed) so far, I get a ZeroDivisionError when
trying to edit a project, and this is apparently caused by [this
line](https://github.com/python-
pillow/Pillow/blob/master/PIL/TiffImagePlugin.py#L482) in TiffImagePlugin,
which is called by get_thumbnail.

Here's the error traceback

[![enter image description
here](http://i.stack.imgur.com/L0dmq.png)](http://i.stack.imgur.com/L0dmq.png)
[![enter image description
here](http://i.stack.imgur.com/7QCtZ.png)](http://i.stack.imgur.com/7QCtZ.png)

And here's my code (note I'm also using admin-sortable but I don't think
that's related):

    
    
    from django.contrib.admin.widgets import AdminFileWidget
    from django.utils.safestring import mark_safe
    from django.forms import ModelForm
    from sorl.thumbnail import get_thumbnail
    from models import Image
    
    class AdminImageWidget(AdminFileWidget):
        def render(self, name, value, attrs=None):
            output = []
            if value and getattr(value, "url", None):
              t = get_thumbnail(value,'80x80')
              output.append('<img src="{}">'.format(t.url))
            output.append(super(AdminFileWidget, self).render(name, value, attrs))
            return mark_safe(u''.join(output))
    
    class ImageForm(ModelForm):
        class Meta:
            fields = '__all__'
            model = Image
            widgets = {
              'img': AdminImageWidget,
            }
    
    class ImageInline(SortableStackedInline):
        model = Image 
        extra = 3
        form  = ImageForm
    
    class ProjectAdmin(NonSortableParentAdmin):
        list_display = ('name', 'description')
        inlines = [ImageInline]
        list_filter = ('type',)
        search_fields = ('name', 'description')
    

Note this doesn't happen all the time, it only happens when trying to edit a
_specific_ project (and I'm assuming it might happen with others as well, but
so far couldn't find more examples).

Any ideas? Thanks in advanced!


Answer: Got same error, update Pillow, it helps.

    
    
    $ pip install pillow --upgrade
    

