[Answered ]-Display the image in the django-tables2

1👍

If you look at the docs, there is an example to subclass an img column.

https://django-tables2.readthedocs.io/en/latest/pages/custom-data.html#subclassing-column

from django.utils.html import format_html

class ImageColumn(tables.Column):
    def render(self, value):
        return format_html('<img src="/media/img/{}.jpg" />', value)

You could also have a custom render function:

https://django-tables2.readthedocs.io/en/latest/pages/custom-data.html#table-render-foo

def render_img_column(self, record, value):
    return mark_safe(f"<img src='{record.url}' />")
👤Ben

Leave a comment