小编ion*_*u77的帖子

是否有一个降价友好的替代"truncatechars:x"?

经典任务是显示博客帖子列表,包括每篇帖子的简短摘要.

正如我在网上看到的,最常见的方法是截断原始博客文章的内容.

所以我的post_list.html模板看起来像这样:

{% load custom_markdown %}

<div class="col-sm-12">
 <p>
  <small>
   {{ post.text | custom_markdown | truncatechars:160 }}
  </small>
 </p>
</div>
Run Code Online (Sandbox Code Playgroud)

如果我截断markdown有时html标签没有正确关闭 - 结束标记被截断 - 整个html页面都搞砸了.

有截断的智能方法还是我需要编写自己的函数?

PS我最接近的是这个stackoverflow帖子:如何截断Ruby/Rails中的markdown.

django django-templates python-2.7

4
推荐指数
1
解决办法
158
查看次数

标签 统计

django ×1

django-templates ×1

python-2.7 ×1