[英]Embedded python code in Bottle template - simple comparison using “if” statement
I have following bottle template code to show my table: 我有以下瓶子模板代码来显示我的表:
<tbody>
%for row in rows:
<tr>
%for col in row:
<td>{{col}}</td>
%end
</tr>
%end
</tbody>
I would like to check all my cells and change their look if they do not contain "Some string": 我想检查我所有的单元格,如果它们不包含“某些字符串”,请更改它们的外观:
if col == "Some string":
<td>{{col}}</td>
else:
<td class="table-danger">{{col}}</td>
Do I need to do comparisons in a template (frontend) or in my "engine" (backend)? 我需要在模板(前端)或“引擎”(后端)中进行比较吗?
You can do it in template like : 您可以在模板中执行以下操作:
<tbody>
%for row in rows:
<tr>
%for col in row:
<td {{'class=table-danger' if col == "Some string" else ""}}>
{{col}}
</td>
%end
</tr>
%end
</tbody>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.