嗨,这是我比较两部手机技术规格的代码。
def getFormValues(request):
if ('mobile_a' in request.GET and request.GET['mobile_a']) and ('mobile_b' in request.GET and request.GET['mobile_b']):
mobile_a = request.GET['mobile_a']
mobile_b =request.GET['mobile_b']
# calling the mark calculation function
return calculateMark(mobile_a, mobile_b)
else:
message ='You submitted an empty form.'
return HttpResponse(message)
def calculateMark(mobile_a, mobile_b):
#variables
mobile_a = mobile_a
mobile_b = mobile_b
tech_mark_a= 0
tech_mark_b = 0
results_a = []
results_b = []
record_a = TechSpecificationAdd.objects.filter(mobile_name=mobile_a).values()
record_b = TechSpecificationAdd.objects.filter(mobile_name=mobile_a).values()
results_a += record_a
results_b += record_b
#dimension
if int(record_a["dimension"]) > int(record_b["dimension"]):
tech_mark_a = 1
else:
tech_mark_b = 1
#body-material
#weight
if record_a["weight"] > record_b["weight"]:
tech_mark_b += 1
else:
tech_mark_a += 1
#camera
if record_a["camera"] > record_b["camera"]:
tech_mark_a += 1
else:
tech_mark_b += 1
#flash
if (record_a["flash"]):
tech_mark_a += 1
if (record_b["flash"]):
tech_mark_b += 1
#video
if record_a["video"] > record_b["video"]:
tech_mark_a += 1
else:
tech_mark_b += 1
#fps
if record_a["fps"] > record_b["fps"]:
tech_mark_a += 1
else:
tech_mark_b += 1
#front-camera
if record_a["front_camera"] > record_b["front_camera"]:
tech_mark_a += 1
else:
tech_mark_b += 1
return render_to_response('degrees_result.html', {'data_a': results_a, 'data_b': results_b})在这种情况下,django调试显示了错误"TypeError at /calculate/ No exception“。如果你想要回溯信息,我可以提供。
那么问题是什么呢?我搞不懂。
发布于 2013-12-26 03:16:42
QuerySet.values返回ValuesQuerySet对象(类似于字典列表)
record_a = TechSpecificationAdd.objects.filter(mobile_name=mobile_a).values()但是,代码使用它就好像它是一个字典:
int(record_a["dimension"])将这类用法转换为:
int(record_a[0]["dimension"])或将record_a转换为字典:
record_a = record_a[0]https://stackoverflow.com/questions/20778657
复制相似问题