【发布时间】:2014-09-10 17:58:18
【问题描述】:
我的 django1.4 模板中有一个字符串,我想用空格替换换行符。我只想用模板字符串中的单个空格替换换行符。
到目前为止,我在 django docs、Google 和 SO 上的所有搜索都没有给我答案。
这是我模板中的字符串:
{{ education_detail.education_details_institution_name|safe|truncatechars:20|striptags }}
当我保存了以下字符串时:
University
Bachelor of Something
2008 - 2010
django模板中的字符串渲染为:
UniversityB...
我想用 yB 之间的空格替换换行符,如下所示:
University B...
我该怎么做?
【问题讨论】:
-
你看过
truncatechars_html吗?我认为这可以用来代替|safe|truncatechars
标签: django string replace django-templates newline