1

我正在从存储目录中读取一个 html 文件,用漂亮的汤做一些修改,然后使用 HttpResponse 输出结果。我的问题是某些字符(例如 <> 符号)作为 ascii 代码而不是符号返回,例如 < 而不是 <

为了消除我使用 BeautifulSoup 进行更改的任何机会,我将其简化为基础。这有效:

file = default_storage.open(fileLocation, 'r')
html = file.read()

HttpResponse(html)

这不会:

file = default_storage.open(fileLocation, 'r')
html = file.read()
soup = BeautifulSoup(html)

HttpResponse(str(soup))

这绝不代表我对此的唯一尝试。我梳理了 BeautifulSoup 文档并尝试了几种不同的编码方法,但结果相同。

4

0 回答 0