当我在管理文件中执行以下操作时:
photo = Photo.objects.get(original_image__exact=file_name)
val = photo.admin_thumbnail.url
我收到此错误:
Caught DoesNotExist while rendering: Photo matching query does not exist.
这是我的课:
class AdminImageWidget(forms.FileInput):
"""
A ImageField Widget for admin that shows a thumbnail.
"""
def __init__(self, attrs={}, *args, **kwargs):
super(AdminImageWidget, self).__init__(attrs)
def render(self, name, value, attrs=None):
output = []
file_name = unicode(value)
if file_name:
photo = Photo.objects.get(original_image__exact=file_name)
val = photo.admin_thumbnail.url
output.append(('<a target="_BLANK" href="%s">'
'<img src="%s" /></a> '
% (val, val)))
output.append(super(AdminImageWidget, self).render(name, value, attrs))
return mark_safe(u''.join(output))
但是,如果我在 shell (python manage.py shell) 中执行此操作,它会完美运行!
奇怪吧?