【发布时间】:2012-04-09 22:03:32
【问题描述】:
我在view.py 中有一个函数,它返回两个变量,即一个名为ca 的字典和一个名为categories 的列表:
def eventcateg_detail(request):
ca = EventTypeCategory.objects.values()
categories =[]
for i in range(0, len(ca)):
pk_sub = ca[i]['sub_categ_id']
if (pk_sub!=None):
category = EventTypeCategory.objects.get(id = pk_sub)
category = category.name
categories.append(category)
return render(request,"events/categ.html",{
'obj': ca,
'categ' :categories
})
categ 返回:
[u'Critical in list', u'Information in list', u'Amit Pal in list']
我的categ.html 是:
<thead>
<tr><th>{% trans "Name Category" %}</th><th>{% trans " Message" %}</th><th>{% trans "Sub-categories" %}</th></tr>
</thead>
<tbody>
{% for obj in obj %}
<tr>
<td>{{ obj.name }}</td><td> {{ obj.Message_slug }}</td><td></td>
</tr>
{% endfor %}
</tbody>
</table>
我的输出应该是:
Event Category Event Message Sub-categories
Critical critical critical in list
Information information information in list
Amit Pal amit-pal amit pal in list
子类别包含来自列表的数据。我得到Event Category(使用obj.name)和Event Message(使用obj.Message_slug)是对的,但我无法找到任何方法将子类别也放在同一个td和相同的for循环中(看模板)。
【问题讨论】:
-
匿名投票者,为什么讨厌?这不是一个坏问题。
标签: python django django-templates django-views