django 报错“int() argument must be a string or a number, not 'SimpleLazyObject'”

                                                         django登录页面报错

报错信息“int() argument must be a string or a number, not 'SimpleLazyObject'”

修改代码: Change user=request.user to user=request.user.id:

原来代码:

def home(request):
    tests = TestCase.objects.filter(user=request.user)

    user_counts = TestCase.objects.filter(user=request.user).count()
    #user_scripts = TestCase.objects.filter()
return TemplateResponse(request, 'home.html', {"tests": tests ,"user_counts":user_counts })

修改为:

def home(request):
    tests = TestCase.objects.filter(user=request.user.id)
    user_counts = TestCase.objects.filter(user=request.user.id).count()
    #user_scripts = TestCase.objects.filter()
return TemplateResponse(request, 'home.html', {"tests": tests ,"user_counts":user_counts })

 参考页面:http://stackoverflow.com/questions/20534577/int-argument-must-be-a-string-or-a-number-not-simplelazyobject

猜你喜欢

转载自km-moon11.iteye.com/blog/2215895