请看下面的代码:
{% for row in df_src.iterrows %}
<tr >
<td><input type="checkbox"></td>
{% for col in columns %}
<td class="redrow">{{row.1.col}}</td>
{% endfor %}
</tr>
{% endfor %}
Here in {{row.1.col}}
where col
可以是任何值,例如NAME
, PHONE
等当我像这样访问它时{{row.1.PHONE}}
我得到了 html 中的值,但是当我像这样访问它时{{row.1.col}}
html 中没有显示任何内容。
你不能以这种方式访问它,djangos 模板语言不允许这样做。看这个帖子 https://stackoverflow.com/questions/8000022/django-template-how-to-look-up-a-dictionary-value-with-a-variable@BearBrown 在他的评论中提到。
你可以自己写自定义模板过滤器 https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/#writing-custom-template-filters
like 这个答案 https://stackoverflow.com/a/8000091/9225671 shows:
from django.template.defaulttags import register
...
@register.filter
def get_item(dictionary, key):
return dictionary.get(key)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)