简体   繁体   English

flask app无法正确呈现html标签

[英]flask app not rendering html tags properly

I have a sentence 我有一句话

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>

to make it render properly at front-end here is what I have done 这是我在前端正确渲染的原因

from flask import Markup
sentence = Markup(sentence)

But the output is only rendered properly for one markup (not necessarily first one) and others are not rendered. 但输出只能为一个标记(不一定是第一个)正确呈现,而其他标记不会呈现。

            <p> Reading, watching or <span class="matching">listening</span> to the media isn’t &lt;span class=&#34;matching&#34;&gt;much&lt;/span&gt; help either. </p>

What am I doing it wrong here? 我在这做错了什么?

The culprit is the 罪魁祸首是

isn't

that "'" is not valid ASCII, because of which it doesn't come in the valid range of characters of HTML Markup , thus it escapes it (though it should throw an error) “'”不是有效的ASCII,因为它没有进入HTML标记的有效字符范围,因此它会逃避它(尽管它应该抛出错误)

Hope that solves the issue. 希望能解决这个问题。

This works for me 这适合我

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)

returns 回报

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>')

hope that is what is the required output 希望这就是所需的输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM