我想登錄在用下面的代碼一個用戶:Django的登錄拋出一個「<類型‘exceptions.AttributeError’>」異常
try:
user = User.objects.get(username = username)
print "user found"
if user.password == password and user.is_active:
print "user: " + str(user)
try:
print "test1"
login(request, user)
print "test2"
except:
print "error"
import sys
print "--> " + str(sys.exc_info()[0])
raise
user_is_valid = True
print "hell yeah!!"
except:
user = None
print "failed"
與活動用戶登錄時什麼給出以下控制檯輸出:
user found
user: [email protected]
test1
error
--> <type 'exceptions.AttributeError'>
failed
用戶名是電子郵件地址,但我看不出有什麼問題。用戶處於活動狀態,您可以看到用戶對象不是無。爲什麼登錄方法拋出壞的屬性異常,我該如何解決這個問題?
請打印異常的文本表示和回溯。回溯模塊應該可以幫助你做到這一點。 – 2011-06-01 10:17:11