Django类型错误没有提供异常

时间:2013-12-26 03:11:08

标签: python django django-models

HI这是我的比较两个手机技术规范的代码

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 debug显示错误“TypeError at / calculate_mark / 没有例外提供“。如果您要求Traceback信息,那么我可以提供。

那么问题是什么?我无法理解。

1 个答案:

答案 0 :(得分:2)

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]