【发布时间】:2016-10-18 05:02:58
【问题描述】:
经典任务是显示博客文章列表,包括每篇文章的简短摘要。
正如我在网上看到的,最常见的方法是截断原始博客文章的内容。
所以我的post_list.html 模板看起来像这样:
{% load custom_markdown %}
<div class="col-sm-12">
<p>
<small>
{{ post.text | custom_markdown | truncatechars:160 }}
</small>
</p>
</div>
如果我截断 markdown,有时 html 标签没有正确关闭 - 结束标签被截断 - 整个 html 页面都变得一团糟。
有没有智能的截断方法或者我需要编写自己的函数?
PS 我得到的最接近的是stackoverflow post: how to truncate markdown in Ruby/Rails。
【问题讨论】:
标签: django python-2.7 django-templates markdown