我有一本字典:
field =
{
u'Birthday:': [datetime.date(2012, 4, 6), datetime.date(2012, 4, 27)],
u'Education': [u'A1', u'A2'],
u'Job:': [u'job1', u'job2'],
u'Child Sex:': [u'M', u'F']
}
我的模板代码是:
<table width="100%" border="0">
<tr>
{% for k, v in field.items %}
<th>{{ k }}</th>
{% endfor %}
</tr>
<tr>
{% for k,v in field.items %}
<td>
<table width="100%" border="0">
{% for a in v %}
<tr class="{% cycle 'odd' 'even' %}"><td>{{ a }}</td></tr>
{% endfor %}
</table>
</td>
{% endfor %}
</tr>
</table>
我想将字典键显示为表头,将 esach 值显示为行:
Birthday Education Job Child Sex
datetime.date(2012, 4, 6) A1 job1 M
datetime.date(2012, 4, 27) A2 job2 F
但我必须插入第二个表。有没有办法将字典键显示为表头,将 esach 值显示为行?
提前致谢