Python tal:条件未执行条件检查
我有下面的tal条件代码,理论上应该可以工作,但它不执行条件检查。窗体点击此条件,运行它,然后返回一个被0除的除法错误,而不是0 我故意处理不完整的数据,这是为了确保不会生成错误页,表中的单元格只显示0Python tal:条件未执行条件检查,python,zope,template-tal,zpt,Python,Zope,Template Tal,Zpt,我有下面的tal条件代码,理论上应该可以工作,但它不执行条件检查。窗体点击此条件,运行它,然后返回一个被0除的除法错误,而不是0 我故意处理不完整的数据,这是为了确保不会生成错误页,表中的单元格只显示0 <td style="text-align: right;"> <span tal:condition="python:result.sum_adt_out<>0"> <span tal:replace="p
<td style="text-align: right;">
<span tal:condition="python:result.sum_adt_out<>0">
<span tal:replace="python:'%.1f'%((float(result.sum_cenmn) or 0)/float(result.sum_adt_out))">currentindex</span></span>
<span tal:condition="python:result.sum_adt_out==0">
<span tal:replace="python:'%.1f'%(0.0)"></span></span>
</td>
当前索引
如果有人有任何想法,我们将不胜感激 如果
result.sum\u adt\u out
属性是字符串,则测试将失败
还请注意,Python中已弃用了
,请使用=代码>改为测试不平等性。您的模板经过简化,首先对值调用float()
,以确保其为数字,然后变为:
<td style="text-align: right;" tal:define="sum_adt_out python:float(result.sum_adt_out)">
<span tal:condition="sum_adt_out"
tal:content="python:'%.1f' % (float(result.sum_cenmn)/sum_adt_out,)">currentindex</span>
<span tal:condition="not:sum_adt_out">0.0</span>
</td>
当前索引
0