Answers for "django admin image"

0

django admin image

from django.utils.html import format_html

@admin.register(Model1) 
class Model1Admin(admin.ModelAdmin):

    def image_tag(self, obj):
        return format_html('<img src="{}" />'.format(obj.image.url))

    image_tag.short_description = 'Image'

    list_display = ['image_tag',]
Posted by: Guest on January-11-2021
0

django show image in admin page

in main URL:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Posted by: Guest on April-11-2020

Python Answers by Framework

Browse Popular Code Answers by Language