Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django类型错误未提供异常_Python_Django_Django Models - Fatal编程技术网

Python Django类型错误未提供异常

Python Django类型错误未提供异常,python,django,django-models,Python,Django,Django Models,嗨,这是我比较两款手机技术规格的代码 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['mobil

嗨,这是我比较两款手机技术规格的代码

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在/calculate_标记处显示错误“TypeError”/ 没有提供例外情况”。如果你要回溯信息,我可以提供

那么问题是什么呢?我搞不懂。

返回
ValuesQuerySet
对象(类似于字典列表)

但代码使用它就像使用字典一样:

int(record_a["dimension"])
record_a = record_a[0]

将这种用法转换如下:

int(record_a[0]["dimension"])
或将
记录作为字典:

int(record_a["dimension"])
record_a = record_a[0]