我試圖設置Parsley.js和Django的前端用戶身份驗證檢查。
這是我的看法AttributeError:'NoneType'對象沒有屬性'is_active'
@requires_csrf_token
def password_check(request):
email = request.POST.get('email')
password = request.POST.get('password1')
user = authenticate(email=email, password=password)
if request.is_ajax():
if user.is_active:
res = "These password and e-mail are ok."
ajax_vars_login = {'response': res, 'email': email, 'password': password}
json_data_login = json.dumps(ajax_vars_login)
else:
res = "The e-mail or the password field aren't correct."
ajax_vars_login = {'response': res, 'email': email, 'password': password}
json_data_login = json.dumps(ajax_vars_login)
return HttpResponse(json_data_login, content_type='application/json')
的驗證
Parsley.addAsyncValidator(
'emailPwCombination', function (xhr) {
var password = $('#password').parsley();
var email = $('#email').parsley();
var response = xhr.responseText;
var jsonResponse = JSON.parse(response);
var jsonResponseText = jsonResponse["response"];
if(jsonResponseText == 'The password and e-mail are ok.')
return true;
if(jsonResponseText == '404')
return false;
}, '/password_check/'
);
但是,當 「password_check」 函數被調用我得到這個錯誤:
AttributeError的在/ password_check/
'NoneType' 對象沒有屬性'is_active'
我試過把打印在「request.is_ajax()」之後測試這些值,它有時會捕獲電子郵件,有時會捕獲電子郵件,但有時會收到密碼,但從未將這兩者結合在一起。
我該如何解決這個問題?
它告訴你,沒有任何東西從'authenticate'返回,大概是因爲電子郵件和密碼不匹配。你應該檢查一下。 –