我是django中的新成員,我正嘗試創建註冊並登錄用戶。我已經完成了註冊頁面,並且有些用戶正在註冊,這些註冊信息存儲在我的數據庫中。當我要登錄時,無法找到已註冊的用戶。你能幫我一下嗎?如何檢查登錄用戶登錄Django?
我view.py
def login_user(request):
state = "Please log in below..."
if request.POST:
email = request.POST.get('email')
password = request.POST.get('password')
user = authenticate(email=email, password=password)
if user is not None:
if request.user.is_authenticated:
login(request, user)
state = "You're successfully logged in!"
else:
state = "Your account is not active, please contact the site admin."
else:
state = 'email: '+str(email)+' and password: '+str(password)+' is not found'
return render_to_response('signup_test.html',{'state':state, 'email': email},context_instance=RequestContext(request))
請閱讀[文檔](https://docs.djangoproject.com/en/1.8/topics/auth/default/#how-to-log-a-user-in)。 –