I want to display the chemical formula of compound with subscript. I have a list of compounds and few of them should be written using subscript. I wrote the following code:
def contains_number(string):
new_string = ''
int_str_list = list(map(str, list(range(9))))
for item in string:
if item in int_str_list:
new_string += '<sub> '+item+' </sub>'
else:
new_string += item
return new_string
This code works and when I pass string like Fe2O3, I get the output like:
Fe<sub>2</sub>O<sub>3</sub> which is what I want.
However, when I pass this as a context variable to Django template, it is not rendered as Fe2O3 but as text Fe<sub>2</sub>O<sub>3</sub> .
Since I am new to Django, I am missing something, I know.
How can I fix this?
Fe<sub>2</sub>O<sub>3</sub>., which if put into plain html will give the subscripted text.itemis user input, you should escape it first, then you can disable autoescape.