断管('127.0.0.1',57124)

时间:2017-02-04 06:19:33

标签: python django mongodb authentication broken-pipe

好吧,我已经编写了以下代码,使用django 1.10和mongoengine 0.9.0(MongoDB)在后端创建登录功能,这里是代码:

@csrf_exempt
def check_auth(request):
   csrf_dict = {}
   csrf_dict.update(csrf(request))
   username = json.loads(request.body)['username']
   password = json.loads(request.body)['pwd']
   try:
     user = User.objects.get(username=username)
     if user.check_password(password):
        user.backend = 'mongoengine.django.auth.MongoEngineBackend'
        user = authenticate(username=username, password=password)
        login(request, user)
        request.session.set_expiry(60 * 60 * 1)
        user_id = str(user.pk)
        print HttpResponse.status_code
        if request.POST.has_key('next'):
            return redirect(request.POST['next'])
        else:
            return redirect('/dashboard/home')
    else:
        return redirect('/dashboard/login')
except DoesNotExist:
    return redirect('/dashboard/login')

响应代码是200,但它没有将页面重定向到主页,而是给了我错误:

[04/Feb/2017 06:00:05] "POST /dashboard/check_auth HTTP/1.1" 302 0
[2017-02-04 06:00:05,223] - Broken pipe from ('127.0.0.1', 57124)

请建议您解决此问题。

1 个答案:

答案 0 :(得分:0)

你可以逐行调试代码吗,

"import pdb; pdb.set_trace()"