Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.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 Views - Fatal编程技术网

Python Django从视图函数调用内部的另一个函数

Python Django从视图函数调用内部的另一个函数,python,django,django-views,Python,Django,Django Views,视图是这样的 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

视图是这样的

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)
if (tech_mark_a == 0 and tech_mark_b == 0):
    mobile_a_infos = TechSpecificationAdd.objects.filter(tech_variables)
    return render_to_response('degrees_result.html', {'mobile_a': tech_mark_a, 'mobile_b': mobile_b}, mobile_a_infos)

elif (tech_mark_a > 0 and tech_mark_b > 0):
    return render_to_response('degrees_result.html', {'mobile_a': tech_mark_a, 'mobile_b': mobile_b})
这里我调用一个函数(calculateMark),它将计算一个标记。在calculateMark函数的末尾,我有这样的东西

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)
if (tech_mark_a == 0 and tech_mark_b == 0):
    mobile_a_infos = TechSpecificationAdd.objects.filter(tech_variables)
    return render_to_response('degrees_result.html', {'mobile_a': tech_mark_a, 'mobile_b': mobile_b}, mobile_a_infos)

elif (tech_mark_a > 0 and tech_mark_b > 0):
    return render_to_response('degrees_result.html', {'mobile_a': tech_mark_a, 'mobile_b': mobile_b})
问题是,当我提交一个空表单时,它将消息显示为getFormValues()。但是当我在表单上提交某些内容时,它显示了一个错误,视图MarkCalculation.views.getFormValues没有返回HttpResponse对象。
我怎样才能解决这个问题?提前感谢。

修复您的
calculateMark()
函数,使其没有任何不返回响应的代码路径。另外,考虑首先将参数转换为数字。< / P>谢谢你的回答。你能详细说明一下程序吗?我该怎么办?提示:
calculateMark(0,25);计算器标记(-3,4)
谢谢,问题解决了。我在calculateMark()函数中犯了一个愚蠢的错误。