为什么我的条件逻辑在Jinja2/CherryPy中无法按预期工作? [英] Why doesn't my condition logic work as expected in Jinja2/CherryPy?

查看:62
本文介绍了为什么我的条件逻辑在Jinja2/CherryPy中无法按预期工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{% if bCat2 == True %}
    <div>True</div>
{% else %}
    <div>False</div>

即使bCat2True,也返回<div>False</div>. 谢谢, 安德鲁

Returns <div>False</div> even when bCat2 is True. Thanks, Andrew

推荐答案

要在模板中测试布尔变量,请在Python中将其转换为字符串

To test a Boolean variable in a template, convert it to a string in Python

str(bCat2)

然后将其与模板中的字符串进行比较

and then compared it to a string in the template

{% if bCat2 == 'True' %}
    <div>True</div>
{% else %}
    <div>False</div>

这篇关于为什么我的条件逻辑在Jinja2/CherryPy中无法按预期工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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