difflib.HTMLDiff.make_file() 的输出未在浏览器中呈现 [英] Output of difflib.HTMLDiff.make_file() not rendered in browser

查看:229
本文介绍了difflib.HTMLDiff.make_file() 的输出未在浏览器中呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 PyMOTWdifflib 给出的两个文本.HtmlDiff.make_file() 用于生成 HTML 输出.然而,当在浏览器中保存和打开时,原始 HTML 会显示而不是呈现为预期的表格.

Using the two texts given by PyMOTW, difflib.HtmlDiff.make_file() is used to produce HTML output. Yet when saved and opened in a browser, the raw HTML is displayed rather than rendered as the expected table.

make_file() 的输出是否格式错误?请参阅此处.

Is the output of make_file() malformed? See here.

Python 2.7

推荐答案

我正在使用 python 3.5,并且我正在获取链接中给出的 html 内容,无需任何修改即可正确呈现.您询问了 make_tablemake_file.这是来自您提供的链接:

I am using python 3.5, and I am getting the html content as given in your link correctly rendered without any modification. You asked about make_table and make_file. This is from the link you have given:

这个例子使用make_table(),它只返回包含差异信息的表标签.make_file() 方法生成一个完整的 HTML 文件作为输出.

This example uses make_table(), which only returns the table tag containing the difference information. The make_file() method produces a fully-formed HTML file as output.

所以您显示的输出来自 make_file(),而不是 make_table().

So the output you have shown is from make_file(), not make_table().

如果你正在使用 django(只是一个疯狂的猜测)试试这个:

If you are using django (just a wild guess) try this:

{% autoescape off %}
    {{ your_html_content }}
{% endautoescape %}

您也可以使用 safe:

{{ your_table_content|safe }}

来自 Django 文档:

From django docs:

将字符串标记为在输出之前不需要进一步的 HTML 转义.当自动转义关闭时,此过滤器不起作用

Marks a string as not requiring further HTML escaping prior to output. When autoescaping is off, this filter has no effect

阅读更多此处这里

这篇关于difflib.HTMLDiff.make_file() 的输出未在浏览器中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆