django模板渲染

1 列表嵌套字典for循环

<table border="1">
    <thead>
        <th >name</th>
        <th>age</th>
        <th>email</th>
    </thead>
    <tbody>
    {% for dict in user_list %}
        <tr>
            <td>{{ dict.name }}</td>
            <td>{{ dict.age }}</td>
            <td>{{ dict.email }}</td>
        </tr>
    {% endfor %}
 
    </tbody>
</table>

  

2 字典嵌套字典for循环

<table border="1">
    <thead>
        <th >name</th>
        <th>tally</th>
    </thead>
    <tbody>
    {% for name,tally in user_dict.items %}
        <tr>
            <td>{{ name }}</td>
            <td>{{ tally }}</td>
        </tr>
    {% endfor %}
    </tbody>
</table>

  

猜你喜欢

转载自www.cnblogs.com/jabbok/p/9275389.html