Why doesn't my condition logic work as expected in Jinja2/CherryPy?

前端 未结 5 1764
春和景丽
春和景丽 2021-01-01 13:10
{% if bCat2 == True %}
    
True
{% else %}
False

Returns

False
5条回答
  •  执念已碎
    2021-01-01 13:37

    I would like to add that if your logic is a bit more complex you might want to read about scopes.

    As mentioned in official documentation:

    As of version 2.10 more complex use cases can be handled using namespace objects which allow propagating of changes across scopes:

    {% set ns = namespace(found=false) %}
    {% for item in items %}
        {% if item.check_something() %}
            {% set ns.found = true %}
        {% endif %}
        * {{ item.title }}
    {% endfor %}
    Found item having something: {{ ns.found }}
    

提交回复
热议问题