我有以下理論上應該可以使用的所有條件代碼,但它沒有執(zhí)行條件檢查。表單達到此條件,運行它,然后返回除以0的除數(shù)錯誤,而不是返回0我故意處理不完整的數(shù)據(jù),這是為了確保不會生成錯誤頁面,表中的單元格僅顯示0。<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>如果有人有任何想法,將不勝感激。
1 回答

有只小跳蛙
TA貢獻1824條經(jīng)驗 獲得超8個贊
如果您的result.sum_adt_out屬性是字符串,則測試將失敗。
另請注意,<>已在Python中棄用,請!=改用來測試不平等。模板經(jīng)過簡化,float()首先調用該值以確保它是數(shù)字,然后變?yōu)椋?/p>
<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/150
提交
取消