請幫助通過用戶名來獲取用戶的密碼如何從數據庫中獲取密碼?
views.py:在日誌
def qwe(request):
if request.method == "POST" and request.is_ajax():
#username = request.POST.get('username', '')
username ="admin"
username_req = User.objects.filter(username=username)
if username_req.exists():
pass = username_req[0].password
return HttpResponse(pass)
錯誤消息是:
IndexError: list index out of range
說明這一點。爲什麼你需要pswd? – 2014-09-22 13:48:53
如果您打算實施pswd重置功能,請參閱此鏈接https://docs.djangoproject.com/en/1.7/_modules/django/contrib/auth/forms/#PasswordResetForm – 2014-09-22 13:55:03
嗯,除了Hasan Ramezani的良好答案,錯誤不是關於密碼,而只是因爲你做了一個空的查詢集過濾器。結果列表爲空,您嘗試訪問索引爲0的項目。 – aRkadeFR 2014-09-24 08:27:39