在我的程序中如果语句没有返回django中的任何对象,则其他语句正在执行

时间:2017-08-23 03:52:52

标签: python django

class wenket(View):
    print "qqqqqqqqqqqqqq"
    def get(self,request):
        number1=request.GET['number']
        print"bbbbbbbbbb",number1
        return self.primenumbdef(number1)
    def primenumbdef(self,number1):
        print"aaaaaaaaaaaaaaaaaaaaaaaa"
        if number1==100:
            return HttpResponse(d({"value of number is 100":number1}))
        else:
           return HttpResponse(d({"value of number is not 100": number1}))

1 个答案:

答案 0 :(得分:1)

您从request.GET['number']对象获取的request是一个字符串('100')。您应该考虑将其投放到int,然后将其与100进行比较。也就是说,

def get(self,request):
    number1 = int(request.GET['number'])
    print"bbbbbbbbbb", number1
    return self.primenumbdef(number1)

或者如果你想抓住number可能不是数字的边缘情况,试试这个:

def get(self,request):
    number1 = request.GET['number']
    try:
        number1 = int(number1)
    except ValueError as e:
        # handle case here
    else:
        print"bbbbbbbbbb",number1
        return self.primenumbdef(number1)