django模板中的别名属性

时间:2017-04-07 20:24:47

标签: django templates variables alias

我们可以在django模板中为属性创建别名吗?我认为这不起作用,但我尝试了{% loan.customer as customer %}

谢谢!

1 个答案:

答案 0 :(得分:2)

您可能想要模板标记。

{% with loan.customer as customer %}     
    <div>{{customer}}</div>
{% endwith %}

这是旧样式,但仍然支持请参阅 django documentation了解新款式和更多信息。

目前,新款式

{% with customer=loan.customer %}