我有一个jinja2if
语句,我在其中检查字典项是否等于id,但是它似乎永远无法正确地或根本没有对其求值。在
以下是我的if
声明:
<select id="deviceTypes" class="inputBoxes" style="height: 25px;">
{% for key, value in deviceTypes.iteritems() %}
{% if deviceTypeID == key %} --> deviceTypeID is defined but this block of code never runs (key is an integer value, it's the id of the option)
<option value="{{key}}" selected>{{deviceTypeID}}</option>
{% else %}
<option value="{{key}}">{{value}}</option>
{% endif %}
{% endfor %}
</select>
你能在支票上加上“不”吗?这将告诉您条件是否为
false
。在{%if not deviceTypeID==key%}
答案是:
很可能您的
deviceTypeID
是从请求中提取的,而仍然是一个字符串。确保它是一个整数:或者更好的方法是,当你从请求中得到它时,把它变成一个整数。许多web框架允许您在检索值时将其转换为整数;Flask允许您执行以下操作:
^{pr2}$例如。在
相关问题 更多 >
编程相关推荐