时间:2020-10-28 17:22:04 | 栏目:Python代码 | 点击:次
直接上代码
定义一个upload_img来返回显示图片的html
定义显示图片说明和allow_tags
mark_safe方法于django.utils.safestring导入
from django.utils.safestring import mark_safe from django.contrib import admin @admin.register(AliOSSFile) class AliOssUploadAdmin(admin.ModelAdmin): def upload_img(self, obj): try: img = mark_safe('<img src="%s" width="50px" />' % (obj.file.url,)) except Exception as e: img = '' return img upload_img.short_description = 'Thumb' upload_img.allow_tags = True list_display = ['id', 'ali_id', 'file', 'upload_img', 'created_time'] readonly_fields = ['upload_img']