我需要对 dict 项目进行排序或以某种方式重新组织 html 表以根据我自己的布局显示数据。
<table>
    <tr>
        <th>title</th>
        <th>name</th>
        <th>quantity</th>
        <th>street 1</th>
        <th>street 2</th>
        <th>county</th>
        <th>city</th>
        <th>country</th>
        <th>postal</th>
        <th>shipping</th>
    </tr>
    {% for order in orders %}
    <tr>
        {% for key, value in order.items %}
        <td>
            {% if key == "title" %}
            {{value}}
            {% endif %}
            {% if key == "name" %}
            {{value}}
            {% endif %}
            {% if key == "quantity" %}
            {{value}}
            {% endif %}
            {% if key == "street1" %}
            {{value}}
            {% endif %}
            {% if key == "street2" %}
            {{value}}
            {% endif %}
            {% if key == "county" %}
            {{value}}
            {% endif %}
            {% if key == "city" %}
            {{value}}
            {% endif %}
            {% if key == "country" %}
            {{value}}
            {% endif %}
            {% if key == "postal" %}
            {{value}}
            {% endif %}
            {% if key == "shipping" %}
            {{value}}
            {% endif %}
        </td>
        {% endfor %}
    </tr>
    {% endfor %}
</table>
订单是带有字典的列表。
因为字典中的项目不再按特定顺序排列,我怎样才能将每个 dict 项目放在适当的列中?
我仍然需要在显示列标题时显示它们。从左到右 - “title”是第一个,“name”是第二个等等。
现在,城市在标题下显示,名称在数量下等等。