flask应用程序无法正确呈现html标签 - python

我有一句话

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 &lt;span class="matching"&gt;much&lt;/span&gt; help either. </p>

我在这里做错了什么?

参考方案

罪魁祸首是

不是

该“’”不是有效的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>')

希望这是所需的输出

Python 3运算符>>打印到文件 - python

我有以下Python代码编写项目的依赖文件。它可以在Python 2.x上正常工作,但是在使用Python 3进行测试时会报告错误。depend = None if not nmake: depend = open(".depend", "a") dependmak = open(".depend.mak&#…

Python ElementTree:在循环中替换元素 - python

我正在尝试创建一个脚本,该脚本循环创建一个xml文件,并为两个元素增加值。 (使用netaddr的IP地址,以及递增的tag / member元素,tag01-tag10)from netaddr import IPNetwork import xml.dom.minidom import lxml.etree as etree import xml.etr…

Python Pandas导出数据 - python

我正在使用python pandas处理一些数据。我已使用以下代码将数据导出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…

如何使用BeautifulSoup在<tr>中捕获特定的<td> - python

尝试从nyc Wiki页面中的高中列表中获取所有高中名称。我已经写了足够多的脚本,可以让我获取包含在高中,学业和入学条件列表的表的<tr>标记中的所有信息-但是我如何才能缩小到我认为的范围内在td[0]内休息(会弹出KeyError)-只是学校的名称?到目前为止我写的代码:from bs4 import BeautifulSoup from ur…

将python scikit学习模型导出到pmml - python

我想将python scikit-learn模型导出到PMML。哪个python软件包最合适?我阅读了有关Augustus的内容,但是我无法使用scikit-learn模型找到任何示例。 python大神给出的解决方案 SkLearn2PMML是 JPMML-SkLearn命令行应用程序周围的薄包装。有关受支持的Scikit-Learn Estimator和…