1 django variables alias templates
我们可以在 django 模板中的属性上创建别名吗?我认为这行不通,但我尝试过 {% loan.customer as customer %}。
谢谢!
您可能需要with template 标签。
{% with loan.customer as customer %}
<div>{{customer}}</div>
{% endwith %}
Run Code Online (Sandbox Code Playgroud)
这是旧样式,但仍然受支持,请参阅 django 文档以了解新样式和更多信息。
目前,新风格
{% with customer=loan.customer %}
Run Code Online (Sandbox Code Playgroud)