difflib.HTMLDiff.make_file() 的输出未在浏览器中呈现
Output of difflib.HTMLDiff.make_file() not rendered in browser
使用PyMOTW给出的两个文本,difflib.HtmlDiff.make_file()
用于产生HTML输出。然而,当在浏览器中保存和打开时,原始 HTML 显示而不是呈现为预期的 table.
make_file()
的输出格式是否错误?参见 here。
Python 2.7
我正在使用 python 3.5,并且我得到 html 内容 如您 link 中给出的那样,无需任何修改即可正确呈现.您询问了 make_table
和 make_file
。这是来自 link 你给的:
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()
。
如果您使用的是 django(只是一个疯狂的猜测)试试这个:
{% autoescape off %}
{{ your_html_content }}
{% endautoescape %}
您也可以使用 safe:
来做同样的事情
{{ your_table_content|safe }}
来自 django 文档:
Marks a string as not requiring further HTML escaping prior to output.
When autoescaping is off, this filter has no effect
使用PyMOTW给出的两个文本,difflib.HtmlDiff.make_file()
用于产生HTML输出。然而,当在浏览器中保存和打开时,原始 HTML 显示而不是呈现为预期的 table.
make_file()
的输出格式是否错误?参见 here。
Python 2.7
我正在使用 python 3.5,并且我得到 html 内容 如您 link 中给出的那样,无需任何修改即可正确呈现.您询问了 make_table
和 make_file
。这是来自 link 你给的:
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()
。
如果您使用的是 django(只是一个疯狂的猜测)试试这个:
{% autoescape off %}
{{ your_html_content }}
{% endautoescape %}
您也可以使用 safe:
来做同样的事情{{ your_table_content|safe }}
来自 django 文档:
Marks a string as not requiring further HTML escaping prior to output. When autoescaping is off, this filter has no effect