django render_to_response mimetypes

时间:2012-04-02 22:27:19

标签: python django character-encoding

我有一个字符串而不是字节<27>(十六进制)来表示'(撇号),使用三个字节<E2><80><99>。 Firefox将其显示为撇号,但是当通过Django的render_to_response函数时,我得到’。其他一些字符也是如此:<E2><80><A6>代表...(省略号)和<E2><80><93>代替-。 Firefox似乎能理解这个三字节表示的名称吗?

'mydata'包含字符串:

render_to_response(mytemplate, mydata, mycontext)

render_to_response(mytemplate, mydata, mycontext, mimetype='text/html')
除了有趣的人物

之外,

有效

render_to_response有一个mimetype参数,如果我知道我的文件的MIME类型是什么,我可以使用它。我试过了

render_to_response(mytemplate, mydata, mycontext, mimetype='application/xhtml+xml')

不会抛出任何永远不会返回的异常。

我有两个问题:(1)我的HTML文件正在使用的字符编码的名称是什么。 (2)mimetype参数是否能够帮助我按照我想要的方式进行渲染?

1 个答案:

答案 0 :(得分:2)

UTF-8,您应该在发送回复之前decode to a unicode

相关问题