gpt4 book ai didi

python - 如何在 django 2.0 admin 中使用 allow_tags?

转载 作者:IT老高 更新时间:2023-10-28 22:23:47 28 4
gpt4 key购买 nike

Support for the allow_tags attribute on ModelAdmin methods is removed.

最佳答案

刚刚找到答案,使用mark_safe功能。

在旧代码中,您可以使用:

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

在新代码中,您应该使用:

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

关于python - 如何在 django 2.0 admin 中使用 allow_tags?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47953705/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com