简体   繁体   English

Django模板中的别名属性

[英]Alias attribute in a django template

Could we make an alias on an attribute in a django template? 我们可以在Django模板中的属性上做一个别名吗? I think this is not work, but I tried {% loan.customer as customer %} . 我认为这是行不通的,但是我尝试了{% loan.customer as customer %}

Thanks! 谢谢!

You probably want the with template tag. 您可能需要with模板标记。

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

this is old style but still supported see the django documentation for new style and more info. 这是旧样式,但仍受支持,有关新样式和更多信息,请参见django文档

For now, New style 目前, 新样式

{% with customer=loan.customer %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM