V
V
Vova1357982021-04-27 14:20:24
Django
Vova135798, 2021-04-27 14:20:24

Why are images not showing up in the Django admin?

For some reason, pictures in the admin panel are not loaded, instead of them, just squares.
And yet, how can I change the name of the get_photo column to something else?
6087f2bbcfa94322137450.png
6087f2f3af826244893189.png

admin.py

class NewsAdmin(admin.ModelAdmin):
    list_display = ('id', 'title', 'category', 'pub_date', 'is_published', 'get_photo')
    list_display_links = ('id', 'title')
    search_fields = ('id', 'title', 'content')
    list_editable = ('is_published', 'category')
    list_filter = ('pub_date','is_published',)

    def get_photo(self, obj):
        if obj.photo:
            return mark_safe(f'<img src="{obj.photo.url}" width="75px">')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2021-05-01
@tumbler

Have you adjusted the static output ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question