Django admin的列表显示如何显示富文本html
How to display rich text html in the list display of Django admin
在models.py
description = models.RichTextField
在admin.py
list_display = ['description']
我的管理面板描述是这样显示的:
<p><strong>bold description: </strong>adding a description</p>
预期是这样的:
粗体描述: 添加描述
Django 初学者将不胜感激
您可以使用 format_html 将您的内容标记为安全
from django.utils.html import format_html
class MyModelAdmin(admin.ModelAdmin):
...
list_display = ['get_description', ]
def get_description(self, obj):
return <b>format_html(obj)</b>
get_description.short_description = 'description'
在models.py
description = models.RichTextField
在admin.py
list_display = ['description']
我的管理面板描述是这样显示的:
<p><strong>bold description: </strong>adding a description</p>
预期是这样的: 粗体描述: 添加描述
Django 初学者将不胜感激
您可以使用 format_html 将您的内容标记为安全
from django.utils.html import format_html
class MyModelAdmin(admin.ModelAdmin):
...
list_display = ['get_description', ]
def get_description(self, obj):
return <b>format_html(obj)</b>
get_description.short_description = 'description'