Django:在模板中分配变量 [英] Django: Assigning variables in template

查看:83
本文介绍了Django:在模板中分配变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I assign a variable inside the django templating system ?

假设 Restaurant 是一个模型:

{%restaurant_id作为restaurant.id%} {{restaurant_id作为restaurant.id }} 不起作用。

推荐答案

您可以使用使用模板标签,并分配一个内部模板变量,如下所示:

You could use the with template tag, and assign an internal template variable like this:

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

这篇关于Django:在模板中分配变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆