2

我的 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
4

1 回答 1

1

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

于 2013-04-21T20:15:38.453 回答