Set allow_tags
attribute:
class MyModel(models.Model):
my_attribute = models.CharField(max_length=50)
def my_link(self):
return '<a href=google.com>google</a>'
my_link.allow_tags = True # <---
According to ModelAdmin.list_display
documentation:
If the string given is a method of the model, ModelAdmin or a callable, Django will HTML-escape the output by default. If you’d rather not escape the output of the method, give the method an allow_tags attribute whose value is True. However, to avoid an XSS vulnerability, you should use format_html() to escape user-provided inputs.