Answer the question
In order to leave comments, you need to log in
Why are thumbnails not showing up in the Django admin?
Only the html tag is displayed.
setting.py
MEDIA_ROOT = '/home/apheyhys/PycharmProjects/jhchase/media/'
MEDIA_URL = '/media/'
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('novels.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
class Cover(models.Model):
name_cover = models.CharField(max_length=100, blank=True, null=True)
cover = models.ImageField()
def image_img(self):
return u'<img src="%s" />' % str(self.cover.url)
image_img.short_description = 'Изображение'
image_img.allow_tags = True
class CoverAdmin(admin.ModelAdmin):
list_display = ("cover", "image_img")
readonly_fields = ("image_img",)
admin.site.register(Cover, CoverAdmin)
Answer the question
In order to leave comments, you need to log in
Try something like this:
from django.utils.safestring import mark_safe
...
def image_img(self):
return mark_safe(u'<img src="%s" />' % str(self.cover.url))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question