我有一句话
sentence = <p> Reading, watching or <span class="matching">listening</span> to the media isn’t <span class="matching">matching</span><span class="matching">much</span> help either. </p>
让我在前端正确渲染这就是我所做的
from flask import Markup
sentence = Markup(sentence)
但输出只能在一个标记中正确呈现(不一定是第一个),而其他标记则不会呈现。
<p> Reading, watching or <span class="matching">listening</span> to the media isn’t <span class="matching">much</span> help either. </p>
我在这做错了什么?
答案 0 :(得分:6)
罪魁祸首是
不是
“”“是无效的ASCII,因为它没有出现在HTML标记的有效字符范围内,因此它会逃脱它(尽管它应该抛出错误)
希望能解决问题。
这对我有用
from flask import Markup
sentence = '<p> Reading, watching or <span class="matching">listening</span> to the media isn\'t <span class="matching">matching</span><span class="matching">much</span> help either. </p>'
Markup(sentence)
返回
Markup(u'<p> Reading, watching or <span class="matching">listening</span> to the media isn\'t <span class="matching">matching</span><span class="matching">much</span> help either. </p>')
希望这就是所需的输出