我想显示带有下标的化合物的化学分子式。我有一个化合物列表,其中很少应该使用下标书写。我写了下面的代码:Django未使用python代码分配标记来呈现html
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
此代码的工作,当我经过串状的Fe2O3,我得到的输出,如: Fe<sub>2</sub>O<sub>3</sub>
这是我想要的。
然而,当我通过此作为上下文变量来Django的模板,它不呈现为铁ø但作为文本Fe<sub>2</sub>O<sub>3</sub>
。
由于我是Django的新手,我错过了一些东西,我知道。
我该如何解决这个问题?
这两个输出对我来说看起来一样,有什么不同?你使用哪些代码作为上下文传递? – Sayse
这就是我的想法。它是在浏览器中呈现的,但是,如果放入纯html中,它将给出下标文本。 –
你应该在django模板中关闭逃脱功能:https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#autoescape – stellasia