如何使用Jinja2进行此循环? [英] How can I make this loop with Jinja2?

查看:102
本文介绍了如何使用Jinja2进行此循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Jinja2,我该如何进行迭代,例如与django而不是Jinja一起使用的跟随:

With Jinja2, how can I make an iteration like the folllowing which works with django and not Jinja:

{% for key,value in location_map_india.items %}
{{value.name}}
{% endfor %}

以上是有效的django,但对于Jinja2,它会返回错误消息

The above is valid django but with Jinja2 it returns an error message

TypeError:"builtin_function_or_method"对象不可迭代

TypeError: 'builtin_function_or_method' object is not iterable

谢谢您的建议

推荐答案

在Jinja2中,函数和方法

In Jinja2, functions and methods must be explicitly called.

{% for key,value in location_map_india.items() %}
{{value.name}}
{% endfor %}

这篇关于如何使用Jinja2进行此循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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