0
我使用Django身份驗證來登錄。我檢查了login()接受2輸入參數請求和用戶的文檔。但是當我實現函數login(request,user)時,錯誤信息顯示這個函數只接受一個輸入參數。我對Django的理解有什麼問題?這是我進口在Django登錄()函數中輸入錯誤的參數號
from django.contrib.auth import *
from django.core.context_processors import csrf
from django.contrib.auth.decorators import login_required
以下是我的代碼
def authuser(request):
username = request.POST.get('username','')
password = request.POST.get('password','')
user = authenticate(username = username,password= password)
if user is not None:
login(request,user)
return HttpResponseRedirect('/timer/clock/')
else:
return HttpResponseRedirect('/timer/login/')
您是否在使用來自django.contrib.auth的登錄信息?你能告訴我們你的進口嗎? –
感謝提醒。是的,我正在使用django.contrib.auth。錯誤消息是「login()只需要1個參數(給出2)」 –
你的應用程序中是否有任何其他名爲login的函數? –