1,使用kindeditor進行了上傳圖片功能,存儲到後臺的html代碼爲:html
<img src="/static/content_img/img_2015-07-21-024421.jpg" alt="" />KindEditor
2,我把這個unicode字符串返回到前臺的模板,結果顯示了html代碼:python
<img src="/static/content_img/img_2015-07-21-024421.jpg" alt="" />KindEditor
3,本身開始的解決辦法:
django
存的時候進行escape測試
content = cgi.escape(content)
這樣處理後存到後臺的代碼變成了:code
<img src="/static/content_img/img_2015-07-21-024421.jpg" alt="" />KindEditor
取的時候unescape一下htm
import HTMLParser html_parser = HTMLParser.HTMLParser() infoContent = html_parser.unescape(info.content)
這樣處理後的代碼變成了:圖片
<img src="/static/content_img/img_2015-07-21-024421.jpg" alt="" />KindEditor
4,可是這樣問題沒有獲得處理,因而本身寫了一個測試,直接把這段html字符串HttpResponse回到頁面,結果顯示正常。unicode
又查了下本身原來處理方式的前臺的源代碼,結果是被轉義後的。因而想到若是經過{{content}}方式在前臺顯示html代碼字符串
的話,django模板在編譯的時候,會自動對html標籤進行轉義,稍微查了下,使用如下方式不讓django模板自動轉義it
html標籤。同時也解決了本身的問題。
{% autoescape off %} {{infoContent}} {% endautoescape %}