我的view.py看起来如下。我认为错误在于此部分。如果目前还不够,我将发布详细功能。基本上,以total为参数的模型是整数类型。

编辑1:编写整个函数,以便可以提供更多帮助。

def subjManip(request):

    c= {}
    c.update(csrf(request))
    subj = None
    c.update(csrf(request))
    if request.method == 'POST':
        form = SubjForm(request.POST)

        if form.is_valid():
               user = request.user
               subj1 = form.cleaned_data['subj1']
               subj2 = form.cleaned_data['subj2']
               subj3 = form.cleaned_data['subj3']

               if subj1 == None and subj2 == None:
                   raise forms.ValidationError("Both subjs cannot be empty")


               tot = float (((float(0.2017 * subj1 )+ float (0.09036 * subj2) + float(0.6309 * subj3) - 5.0269)/ 4.184)
               total =int(tot)

               elif subj1 == None:
                   total = subj1

最佳答案

尝试将tot = (subj1+subj2)/2.2替换为tot = (float(subj1) + float(subj2)) / 2.2

关于python - ValueError:以10为底的int()的无效文字:''无法发现错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16135681/

10-13 08:18