2012-04-02 59 views
0

我有一個字符串,而不是字節<27>(十六進制)來表示'(撇號),使用三個字節<E2><80><99>。 Firefox顯示這是一個撇號,但是當通過Django的render_to_response函數傳遞時,我得到’。一些其他字符也是如此:<E2><80><A6>表示...(elipsis)和<E2><80><93>而不是-。 Firefox似乎明白這個三字節表示的名字嗎?django render_to_response mimetypes

在哪裏 'MYDATA' 包含字符串:

render_to_response(mytemplate, mydata, mycontext) 

render_to_response(mytemplate, mydata, mycontext, mimetype='text/html') 

作品除了奇怪的字符

render_to_responsemimetype參數,我也許可以使用,如果我知道我的文件的MIME類型是什麼。我試過

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

哪個不會拋出任何異常,它只是永遠不會返回。

我有兩個問題:(1)什麼是我的HTML文件正在使用的字符編碼的名稱。 (2)mimetype參數能否幫助我按照需要渲染它?

回答

2

這是UTF-8,你應該在decode to a unicode之前發送回覆。

+0

沒有人說「打印出來」。 – 2012-04-02 22:50:18

+0

它也無法寫入以二進制打開的文件...只是試圖測試它。 – Intra 2012-04-02 22:56:38

+0

您的問題在第二個鏈接中回答。 – 2012-04-02 22:57:18

相關問題