Reputation: 718
I am trying to display some HTML in the Django admin that is pulled from a model field.
There is a model like this:
class MyModel(models.Model):
symbol = models.CharField(unique=True, max_length=100)
symbol_html = models.TextField('Symbol HTML')
...
An admin like this:
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
list_display = ['symbol', 'display_symbol_html'] # overview display fields
# displays non-escaped html
def display_symbol_html(self, obj):
return mark_safe(obj.symbol_html)
display_symbol_html.allow_tags = True
This works for symbols like Ω
but not with HTML tags like this x<sup>2</sup>
. The display does not show the superscript, just reverts the text to x2
.
How does one display the superscript properly in the list view of Django Admin?
ANSWER
Based on the response below, I used the markup from w3schools and Django properly displays it in the Admin interface.
See HTML Unicode UTF-8 for the list of characters.
Upvotes: 1
Views: 1050
Reputation: 969
You can try Unicode subscript and superscripts https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts
Upvotes: 2