0
我試圖創建如下所示的登錄視圖:Django的登錄不起作用
def user_login(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user:
if user.is_active:
login(request, user)
return HttpResponseRedirect('rango/index.html')
else:
return HttpResponse('Your Rango account is disabled!')
else:
print("Invalid login details: {0}, {1}".format(username, password))
return HttpResponse("Invalid login details supplied!")
else:
return render(request, 'rango/login.html', {})
這似乎是這樣做的正確的方式,但是當我嘗試在我的瀏覽器打開網頁,我收到以下錯誤:
TypeError at /rango/login/
login() missing 1 required positional argument: 'user'
Request Method: GET
Request URL: http://localhost:8000/rango/login/
Django Version: 1.9.10
Exception Type: TypeError
Exception Value:
login() missing 1 required positional argument: 'user'
Exception Location: C:\Users\Johannes\tangowithdjango\lib\site-packages\django\core\handlers\base.py in get_response, line 147
Python Executable: C:\Users\Johannes\tangowithdjango\Scripts\python.exe
Python Version: 3.6.0
Python Path:
['C:\\Users\\Johannes\\tangowithdjango\\tango_with_django_project',
'C:\\Users\\Johannes\\tangowithdjango\\Scripts\\python36.zip',
'C:\\Users\\Johannes\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
'C:\\Users\\Johannes\\AppData\\Local\\Programs\\Python\\Python36\\lib',
'C:\\Users\\Johannes\\AppData\\Local\\Programs\\Python\\Python36',
'C:\\Users\\Johannes\\tangowithdjango',
'C:\\Users\\Johannes\\tangowithdjango\\lib\\site-packages']
Server time: Thu, 12 Jan 2017 17:56:38 +0100
有沒有人遇到類似的事情或知道解決方案的問題?我已經搜索並嘗試了一下,但找不到答案。
該錯誤似乎不是來自此代碼。無論如何,請將DEBUG設置爲True,然後顯示完整的回溯。 –