首页 > 解决方案 > 将 python xml 响应打印到 HTML 页面中

问题描述

我的 .py 应用程序从 API 返回 xml 响应,我想将 messageKey 'notFound' 的值写入 .html 页面。

回应前:

<response>
<returncode>FAILED</returncode>
<messageKey>notFound</messageKey>
<message>We could not find a meeting with that meeting ID</message>
</response>

.html 的 EX:

#....
<div class="row">
   <p id="demo"></p>
</div>
#....

请问有什么帮助吗?

标签: pythonhtmlpython-3.x

解决方案


我通过以下方式解决这个问题:

.py:

@flask.route('/admin')
def index():
    return render_template("admin.html", variable=soup)

.html:

<div class="row">
  <p>{{variable}}</p>
</div>

推荐阅读