Django使用标签连接对象列表

时间:2016-01-17 06:16:32

标签: python django

我在一个模板中有一些变量:

<p> {{ area.description }} {{area.boss}} {{area.dept}}

我需要连接它们并计算字符数以设置字符串将被剪切的数字

2 个答案:

答案 0 :(得分:3)

如何连接

{{ area.description|add:area.boss|add:area.dept }} 

如何计算所有字符

{{ area.description|add:area.boss|add:area.dept|length }}

答案 1 :(得分:0)

我解决了:在我的模型中我定义了这个:

.xbUserPanelBox .xbUserPanelMenus .newPosts .navLink
{
@property "xb_user_panel_new_posts";
<xen:if is="{$thread.isNew} AND {$thread.haveReadData}">color: rgb(255, 128, 0);
<xen:else />color: white;</xen:if>
@property "/xb_user_panel_new_posts";
}

在模板中:

  def get_full_information (self): return '%s %s %s' (self.description, self.boss, self.dept) 

这样我就把我需要的字符数量中的字符截断了