需要在blog主页显示文章的摘要, 即显示文章的前面一部分.
article|safe|truncatechars:100 // 截取文章的前100个单词
但问题是, 文章中为了排版可能带有html标记(实际上是使用了markdown语法), 如:
who are you ?<p>I am python </p>
如果不凑巧, 碰巧截取掉了某个html标记, 如变为:
who are you ?<p>I am python //少了个结束标志 '</p>'
那么整个页面都会被破坏.
怎么办呢? 或者, 有更好的方法实现吗?(最好不要用javascript来隐藏或显示)
谢谢大家.
truncatewords_html or truncatechars_html (django 1.7 or above)
1. You can try to add tags to the article manually, such as
In view.py, use object.values() and [0:blog.find('')] to intercept the content before the label.
2. Write the introduction of the article yourself.
Just use markdown filter on the data after truncate