TTT
TTT

Reputation: 4434

How to display subscript letters in Django forms?

I have a very naive question. How to display subscripts in the Django form? For example, letters "OC" are the subscripts. a. Is there a way to add some arguments in the label section? I have tried <sub>oc</sub>, but it was not recognized. b. should I try other functions rather than str ? Thanks for your help!

class KabamInp(forms.Form):
    koc = forms.FloatField(label='koc (mL/g OC)')

class InputPage(webapp.RequestHandler):
    def get(self):
    html=str(kabamInp)
    self.response.out.write(html)
app = webapp.WSGIApplication([('/.*', InputPage)], debug=True)

Upvotes: 2

Views: 741

Answers (1)

Alasdair
Alasdair

Reputation: 308979

You can include html tags in your label if you mark the output as safe.

from django.utils.safestring import mark_safe

class MyForm(forms.Form):
    koc = forms.FloatField(label=mark_safe('koc (mL/g <sub>OC</sub>)')) 

You should always take care when using mark_safe, it can be dangerous when you are dealing with user input. In this case, it should be fine.

Upvotes: 3

Related Questions