JinJa2语法测试2


参考代码:

DOCTYPE html>
<html>
<head>
    <title>JinJa2 Demotitle>
     <link rel="stylesheet" href="{{url_for('static',filename='bootstrap4/css/bootstrap.css')}}" type="text/css">
     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.2/font/bootstrap-icons.css">
head>
<body>
<div class="container mt-2">
<h2>JinJa2 Table Demoh2>
    {% set student=[
        {"name":"张三","sex":"男","math":80},
        {"name":"李四","sex":"男","math":99},
        {"name":"王麻子","sex":"男","math":100},
        {"name":"赵莎莎","sex":"女","math":85.45},
        {"name":"王伟","sex":"男","math":52},
        {"name":"赵燕","sex":"女","math":91},
        {"name":"王红兵","sex":"男","math":80},
        {"name":"姚猪猪","sex":"女","math":57.45}
    ] %}
    <table class="table table-striped table-hover">
    <thead>
        <tr>
          <th scope="col">编号th>
          <th scope="col">姓名th>
          <th scope="col">性别th>
          <th scope="col">数学th>
        tr>
    thead>
    <tbody>
        {% for stu in student|sort(attribute="math",reverse=true) %}
            <tr>
                <td>{{ loop.index}}td>
                <td><i class="bi bi-person">i>{{ stu.name }}td>
                <td>
                    {% set genderIcon="bi-gender-male" %}
                    {% if stu.sex!="男" %}
                    {% set genderIcon="bi-gender-female" %}
                    {% endif %}
                      <i class="{{genderIcon}}">i>{{stu.sex}}
                td>
                {% if stu.math<60 %}  
                ="text-danger"><i class="bi bi-bookmark-check">i> {{stu.math}}td> 
                {% else %}
                 <td>{{stu.math}}td> 
                {% endif %}           
            tr>
        {% endfor %}
    tbody>
   table>   
div>
body>
html>