【发布时间】:2018-05-28 19:25:55
【问题描述】:
我有以下字典:
d = {'21': 'test1', '11': 'test2'}
{% with '18 17 16 15 14 13 12 11 21 22 23 24 25 26 27 28' as list_upper %}
{% for x in list_upper.split %}
{% if x in dental_position %}
<input type="text" placeholder = "{{ x }}" class="form-control" name="tooth[]" value="{{display dict.value here}}">
{% else %}<input type="text" placeholder = "{{ x }}" class="form-control" name="tooth[]">
{% endif%}
{% endfor %}
当在list_upper 中找到来自d[key] 的值时,我想在输入文本值属性中显示d[value]
如何在 django 模板中调用{% if d.keys in x %}?
【问题讨论】:
-
这里需要一个 django 模板tag。这将使这个问题变得相当简单。
-
您没有在上下文中定义
list_upper有什么原因吗?您不必为 for 循环在模板中进行疯狂的编码。
标签: python django django-templates