【发布时间】:2014-01-13 02:04:59
【问题描述】:
你好,我是新手程序员
def calculateMark(mobile_a, mobile_b):
mobiles_list = [mobile_a, mobile_b]
for mobile in mobiles_list:
dimension = TechSpecificationAdd.objects.filter(mobile_name = mobile).values(dimension)
body_material = TechSpecificationAdd.objects.filter(mobile_name = mobile).values(body_material)
weight = TechSpecificationAdd.objects.filter(mobile_name = mobile).values(weight)
tech_variables = {'dimension' : dimension, 'body_material' : body_material, 'weight' : weight}
return render_to_response('compare.html', tech_variables)
我有这样的东西,一个移动设备列表,从数据库中分配值,然后在字典中分配变量。我正在考虑遍历字典并在模板中显示值。 但问题是我必须制作模板以在一页中显示两个手机信息以进行比较。如何在模板中一次显示两个手机信息?我认为模板将始终显示一部手机的信息。 其实我有点卡在这里,我不知道现在该怎么办。 我从一开始就错了吗?我需要字典吗?如何迭代或分配值以在模板中显示。还是我在问一个愚蠢的问题?
【问题讨论】:
标签: python django dictionary django-templates django-views