authenticate() takes exactly 0 arguments (2 given)

来源:6-2 用户登录-1

一一倾

2017-07-28

不知道怎么处理:

TypeError at /login/

authenticate() takes exactly 0 arguments (2 given)

Request Method:

POST    

Request URL:

http://127.0.0.1:8000/login/    

Django Version:

1.9.8    

Exception Type:

TypeError    

Exception Value:

authenticate() takes exactly 0 arguments (2 given)
   

Exception Location:

C:\Users\Administrator\PycharmProjects\MxOnline\apps\users\views.py in login, line 9    

Python Executable:

C:\Users\Administrator\Envs\mxonline\Scripts\python.exe    

Python Version:

2.7.13    

Python Path:

['C:\\Users\\Administrator\\PycharmProjects\\MxOnline\\extra_apps',
'C:\\Users\\Administrator\\PycharmProjects\\MxOnline\\apps',
'C:\\Users\\Administrator\\PycharmProjects\\MxOnline',
'C:\\Users\\Administrator\\PycharmProjects\\MxOnline',
'C:\\Users\\Administrator\\PycharmProjects\\MxOnline\\extra_apps',
'C:\\Users\\Administrator\\PycharmProjects\\MxOnline\\apps',
'C:\\Windows\\system32\\python27.zip',
'C:\\Users\\Administrator\\Envs\\mxonline\\DLLs',
'C:\\Users\\Administrator\\Envs\\mxonline\\lib',
'C:\\Users\\Administrator\\Envs\\mxonline\\lib\\plat-win',
'C:\\Users\\Administrator\\Envs\\mxonline\\lib\\lib-tk',
'C:\\Users\\Administrator\\Envs\\mxonline\\Scripts',
'c:\\python27\\Lib',
'c:\\python27\\DLLs',
'c:\\python27\\Lib\\lib-tk',
'C:\\Users\\Administrator\\Envs\\mxonline',
'C:\\Users\\Administrator\\Envs\\mxonline\\lib\\site-packages']
   

Server time:

星期五, 28 七月 2017 15:54:24 +0800    

Traceback Switch to copy-and-paste view

C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\core\handlers\base.py in get_response

▶ Local vars

                   response = self.process_exception_by_middleware(e, request)

...

C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\core\handlers\base.py in get_response

▶ Local vars

                   response = wrapped_callback(request, *callback_args, **callback_kwargs)

...

C:\Users\Administrator\PycharmProjects\MxOnline\apps\users\views.py in login

▶ Local vars

       user = authenticate(user_name, pass_word)

...

我的代码:

from django.contrib.auth import authenticate, login
from django.shortcuts import render


def login(request):
   if request.method == "POST":
       user_name = request.POST.get("username", "")
       pass_word = request.POST.get("password", "")
       user = authenticate(user_name, pass_word)
       if user is not None:
           login(request, user)
           return render(request, "index.html")
   elif request.method == "GET":
       return render(request, "login.html", {})


写回答

1回答

一一倾

提问者

2017-07-28

其实下一节课会讲,只不过在这里停下来的话会遇到问题。


     

3
1
bobby
好的,
2017-07-31
共1条回复

Python3.6+django+xadmin,打造在线教育平台

【毕设】Python 2.7到3.6 完美适配,Django升级2.0

3677 学习 · 4038 问题

查看课程