Django Admin Show Image from Imagefield

Sure. In your model class add a method like:

def image_tag(self):
    from django.utils.html import escape
    return u'<img src="https://stackoverflow.com/questions/16307307/%s" />' % escape(<URL to the image>)
image_tag.short_description = 'Image'
image_tag.allow_tags = True

and in your admin.py add:

fields = ( 'image_tag', )
readonly_fields = ('image_tag',)

to your ModelAdmin. If you want to restrict the ability to edit the image field, be sure to add it to the exclude attribute.

Note: With Django 1.8 and ‘image_tag’ only in readonly_fields it did not display. With ‘image_tag’ only in fields, it gave an error of unknown field. You need it both in fields and in readonly_fields in order to display correctly.

Leave a Comment