How can I show external links in the Django admin interface?

I need to create external links in the grid column of the admin interface, but they appear as html code:

<a href="http://www.site.com/">site</a>

The Admin interface translates my links as html entities, and they do not appear as valid links. Is it possible to display external links there, and not HTML code?

I think list_display_links is not working for this purpose.

Thanks!

+3
source share
2 answers

Just go to http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display

def colored_name(self):
    return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
colored_name.allow_tags = True
+9
source

Django 2.0 - HTML. format_html(), Django .

from django.utils.html import format_html

def my_link_field(self):
    return format_html(
            '<a href="{0}">{1}</a>',
            self.my_external_url,
            self.my_link_display_name,
        )
+1

Source: https://habr.com/ru/post/1706168/


All Articles