Is there any way for django admin to display html? on the add database fields page


admin K2O

clipboard.png
using verbose_name will directly display it as text, which is not successful

found that there is a format_html () method, but it doesn"t seem to work here
can only be used on list_display ()


this method, which needs to override the parent class, makes the verbose_name tag a safe string.

class MarkSafeCharField(models.FloatField):
    def formfield(self, **kwargs):
        kwargs['label'] = mark_safe(self.verbose_name)
        return super().formfield(**kwargs)
        
-sharp 
name= MarkSafeCharField(verbose_name='K<sub>2</sub>0')

you can see what you want:

Menu