2017-02-04 70 views
0

嗯,我寫了下面的代碼使用Django 1.10和mongoengine 0.9.0(MongoDB的),使在後臺登錄的功能,這裏是代碼:從管道中斷(「127.0.0.1」,57124)

@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) 

請建議解決這個問題。

+0

看一看此相關的問題:https://stackoverflow.com/questions/7912672/django-broken-pipe-in​​-debug-mode – Pierz

回答

0

可以調試行的代碼行,

"import pdb; pdb.set_trace()" 
+0

嗯,我已經嘗試過,但它沒有拋出任何錯誤 –