我试图有两个Tal条件语句,检查代码是否是两件事之一,然后执行相应的计算。但是它会同时打印出两个条件的结果。你知道吗
谢谢!你知道吗
Unit 4.5522 0.0000
unit.. . 3.7628 0.0000
Unit 0.0000 14.6083
unit 0.0000 31.9430
<td style="text-align: right;">
<span tal:condition="python:float(result.totdirrn)!=0 and (result.wkld1_desc!='Proceedures' and result.wkld1_desc!='Visits')">
<span tal:replace="python:'%.4f'%(float(result.cenmn)/((((float(result.dirhrs)*(float(float(result.totdirrn)/float(result.dirhrs))))/14)/12)/2))">currentindex</span>
<span tal:condition="python:float(result.totdirrn)!=0 and (result.wkld1_desc!='Census')">
<span tal:replace="python:'%.4f'%(float(result.vipr)/((((float(result.dirhrs)*(float(float(result.totdirrn)/float(result.dirhrs))))/14)/12)/2))">currentindex</span></span>
</span>
<span tal:condition="python:(float(result.totdirrn)==0)">
<span tal:replace="python:'%.1f'%(0.0)"></span></span>
</td>
你想要做什么,或者你期望的结果是什么,这是相当不清楚的。我已经解决了您的模板代码的一般问题,让我们看看这是否解决了您的问题:
似乎你的开始和结束
<span/>
标签搞混了。当前您的结构如下所示:我怀疑你真的想:
您可以将条件范围与
tal:content
属性组合起来,而不是替换嵌套的<span>
标记,形成:或者,应用到您的示例代码中,进行一些改进,使其更具可读性:
您可能需要确保那些
float
结果已经是浮点值,并避免视图中所有的float()
调用。你知道吗还要考虑到浮点值可能不是0,如果要求逗号后面的精度为4位,则
0.000001
的值不等于0
,而是打印为0.000
。你知道吗相关问题 更多 >
编程相关推荐