gpt4 book ai didi

Django:在模板中分配变量

转载 作者:行者123 更新时间:2023-11-28 19:34:13 24 4
gpt4 key购买 nike

如何在 Django 模板系统中分配变量?

假设 Restaurant 是一个模型:

{% restaurant_id as restaurant.id %}{{ restaurant_id as restaurant.id }} 无效。

最佳答案

您可以使用 with template tag ,并像这样分配一个内部模板变量:

{% with restaurant_id=restaurant.id %}
... use restaurant_id in this template section ...
{% endwith %}

关于Django:在模板中分配变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8517933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com