diff --git a/wagtail/wagtailimages/templatetags/image_tags.py b/wagtail/wagtailimages/templatetags/image_tags.py index e1324eb9b8..e731cdd2b6 100644 --- a/wagtail/wagtailimages/templatetags/image_tags.py +++ b/wagtail/wagtailimages/templatetags/image_tags.py @@ -1,6 +1,6 @@ from django import template -from wagtail.wagtailimages.models import Filter +from wagtail.wagtailimages.models import Filter, Rendition register = template.Library() @@ -42,7 +42,17 @@ class ImageNode(template.Node): if not image: return '' - rendition = image.get_rendition(self.filter) + try: + rendition = image.get_rendition(self.filter) + except IOError: + # It's fairly routine for people to pull down remote databases to their + # local dev versions without retrieving the corresponding image files. + # In such a case, we would get an IOError at the point where we try to + # create the resized version of a non-existent image. Since this is a + # bit catastrophic for a missing image, we'll substitute a dummy + # Rendition object so that we just output a broken link instead. + rendition = Rendition(image=image, width=0, height=0) + rendition.file.name = 'not-found' if self.output_var_name: # return the rendition object in the given variable