try: body = json.loads(request.body) email = body[u'email'].encode('utf-8') password = body[u'password'].encode('utf-8') user = authenticate(email=email, password=password) except Exception, e: return render(request, 'user/ErrorUrl.html', {'error': '此地址异常'}) try: if user: print user.is_active if user.is_active == False: msg['isSuccess'] = False msg['is_NotActive'] = True msg['error'] = False else: user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, user) msg['isSuccess'] = True msg['error'] = False else: msg['isSuccess'] = False msg['isNotActive'] = False except Exception, e: msg['error'] = True return HttpResponse(json.dumps(msg), content_type="application/json") def user_logout(request): logout(request) return redirect('/')