How to display rich text html in the list display of Django admin

Viewed 845

In models.py

description = models.RichTextField

In admin.py

list_display = ['description']

I admin panel description is displayed like this :

<p><strong>bold description:&nbsp;</strong>adding a description</p>

expected is this: bold description: adding a description

beginner in Django assistance in this would be appreciated

1 Answers

You can use format_html to mark your content as safe

from django.utils.html import format_html

class MyModelAdmin(admin.ModelAdmin):
    ...

    list_display = ['get_description', ]

    def get_description(self, obj):
       return format_html(obj)
    get_description.short_description = 'description'
Related