用的是linux,
首先把model中的代碼改成:
1 def save(self): 2 self.body = self.body.replace("\r\n", "\n") 3 self.body = self.body.replace("\n","</br>|safe") 4 super(Diary, self).save() 5
當然不知道為什么還是沒用。。"<" 和 ">" 還是會被轉義
兩個群都沒有人回答問題啊好凄慘。
先不管這個,把add diary 那個頁面做好再說。
完事兒再查。
---------------------------update-------------------------------
好丟人,,模版內部內置了filter的。
linebreaks
Replaces line breaks in plain text with appropriate HTML; a single newline becomes an HTML line break (<br />) and a new line followed by a blank line becomes a paragraph break (</p>).
For example:
{{ value|linebreaks }}
If value is Joel\nis a slug, the output will be <p>Joel<br />is a slug</p>.
一個filter就搞定了。。要多讀文檔哦