在 Bottle 模板中嵌入 python 代码 - 使用 "if" 语句进行简单比较

Embedded python code in Bottle template - simple comparison using "if" statement

我有以下瓶子模板代码来显示我的 table:

<tbody>
    %for row in rows:
    <tr>
        %for col in row:
        <td>{{col}}</td>
        %end
    </tr>
    %end
</tbody>

我想检查我所有的单元格,如果它们不包含 "Some string":

if col == "Some string":
    <td>{{col}}</td>
else:
    <td class="table-danger">{{col}}</td>

我需要在模板(前端)或 "engine"(后端)中进行比较吗?

您可以在模板中执行此操作,例如:

    <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>