How to test for a List in Jinja2?

后端 未结 4 1178
生来不讨喜
生来不讨喜 2021-01-03 18:33

As far as I can see, there is no way to test if an object is a List instance in Jinja2.

Is that correct and has anyone implemented a custom test/extensio

4条回答
  •  抹茶落季
    2021-01-03 19:27

    I did it like this:

    {% if var is iterable and (var is not string and var is not mapping) %}
    

    You can find a list of all jinja tests here.

提交回复
热议问题