在Django管理后台显示图片缩略图
我想在我的管理后台显示图片缩略图,但我看到的是
<img src="/media/photos/huyase_18638553_orig_.jpeg" width=60 height=60 />
而不是图片。我的模型是:
class RentPhoto(models.Model):
'''
Photos for RentItem
Only one photo could be avatar photo
'''
photo = models.ImageField(_('Photo'), upload_to='photos/')
is_avatar = models.BooleanField(_('Avatar'), default=False)
rentitem = models.ForeignKey(RentItem, related_name='photo')
description = models.CharField(_('Description'), max_length=250)
def thumb(self):
if self.photo:
return u'<img src="%s" width=60 height=60 />' % (self.photo.url)
else:
return u'No image file found'
thumb.short_description = _('Thumbnail')
我的 admin.py 文件是:
class RentPhotoAdmin(admin.ModelAdmin):
fields = ('photo', 'is_avatar', 'rentitem', 'description')
list_display = ('thumb', 'rentitem', 'is_avatar', 'description')
admin.site.register(RentPhoto, RentPhotoAdmin)
我还在我的 urls.py 文件中添加了:
(r'^public/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT}),
当我访问 127.0.0.1:8000/media/photos/huyase_18638553_orig_.jpeg 时,我可以看到图片。这没问题。那么可能出什么问题呢?
附注:我在我的管理网站上使用了 django-grapelli
,这会影响我的图片吗?