How do I use allow_tags in django 2.0 admin?

django, python

Solution

Just found the answer, use `mark_safe` function.

In old code, you may use:

def image_(self, obj):
    return '<image src="%s" />' % obj.image
image_.allow_tags = True

In new code, you should use:

from django.utils.safestring import mark_safe
def image(self, obj):
    return mark_safe('<image src="%s" />' % obj.image)

Problem

Support for the allow_tags attribute on ModelAdmin methods is removed.

Original source