首页 > 解决方案 > 在 HTML 页面中嵌入作为 HTML 的 Python 输出

问题描述

有没有办法可以将此代码嵌入到 HTML 文件中,而不是让它成为文本?如果这是一个糟糕的解释,我很抱歉,但代码和图片应该更好地结合我的想法。

Python:

table = [best_words[0:5]]
p = (tabulate(table, tablefmt='html'))
end = time.time()
final_time = '{:.2f}'.format((end-start))
return render_template('index.html', prediction=('{}'.format(p)), final_time=final_time)

Python的输出:

<table>
<tbody>
<tr><td>the</td><td>a</td><td>,</td><td>-</td><td>that</td></tr>
</tbody>
</table>

HTML 文件:

<h5>Genrated text:</h5>
</div>
<table> <tbody>{{ prediction }} </tbody> </table></div></div> </header>

在此处输入图像描述

标签: pythonhtml

解决方案


使用代码标签

<code>
-- Something here
</code>

推荐阅读