简体   繁体   中英

ValueError: invalid literal for int() with base 10: '' Unable to spot error

My view.py looks as follows. I think the error is in this section. I will post a detailed function if this is not sufficient for now. Basically the model that takes total as argument is of type integer.

Edit 1: Writing the entire function so that it can be more helpful.

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.2tot = (float(subj1) + float(subj2)) / 2.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM