The Guy
The Guy

Reputation: 718

Display superscript in Django Admin

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 &Omega; 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

Answers (1)

Noopur Phalak
Noopur Phalak

Reputation: 969

You can try Unicode subscript and superscripts https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts

Upvotes: 2

Related Questions