'is_staff' is an invalid keyword argument for this function错误处理
1.原因是models.py定义模型没有’is_staff’字段,解决办法是在其中添加
2.或者在定义UserMangen(BaseUserManager),时候少了**kwargs参数
(标红为错误写法)
def create_user(self,telephone,username,password,**kwargs):
kwargs[‘is_superuser’] = False
return self._create_user(telephone=telephone,username=username,password=password,**kwargs)
3.定义models.py中的UserManager将名称写错了,如图上的UserMangen (标红为错误写法)
TypeError at /
‘is_staff’ is an invalid keyword argument for this function
Request Method:
GET
Request URL:
Django Version:
2.1.4
Exception Type:
TypeError
Exception Value:
‘is_staff’ is an invalid keyword argument for this function
Exception Location:
C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\django\db\models\base.py in __init__, line 485
Python Executable:
C:\Users\Administrator\PycharmProjects\untitled\venv\Scripts\python.exe
Python Version:
3.7.1
Python Path:
[‘C:\\Users\\Administrator\\PycharmProjects\\untitled3’,
‘C:\\Users\\Administrator\\PycharmProjects\\untitled3’,
‘C:\\Users\\Administrator\\PycharmProjects\\untitled\\venv\\Scripts\\python37.zip’,
‘C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\DLLs’,
‘C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib’,
‘C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37’,
‘C:\\Users\\Administrator\\PycharmProjects\\untitled\\venv’,
‘C:\\Users\\Administrator\\PycharmProjects\\untitled\\venv\\lib\\site-packages’,
‘C:\\Users\\Administrator\\PycharmProjects\\untitled\\venv\\lib\\site-packages\\setuptools-39.1.0-py3.7.egg’,
‘C:\\Program Files\\JetBrains\\PyCharm ‘
‘2018.1.4\\helpers\\pycharm_matplotlib_backend’]
Server time:
Thu, 3 Jan 2019 22:15:25 +0000
Traceback Switch to copy-and-paste view
C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\django\core\handlers\exception.py
ininner
…response = get\_response(request)
C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\django\core\handlers\base.py
in_get_response
response = self.process\_exception\_by\_middleware(e, request)
...
C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\django\core\handlers\base.py
in_get_response
response = wrapped\_callback(request, \*callback\_args, \*\*callback\_kwargs)
...
C:\Users\Administrator\PycharmProjects\untitled3\front\views.py
inindex
…sd = User.objects.create\_user(telephone='18894148319',username='zhil1ao',email='1111@qq.com',password='1111111')
C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\django\contrib\auth\models.py
increate_user
return self.\_create\_user(username, email, password, \*\*extra\_fields)
...
C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\django\contrib\auth\models.py
in_create_user
user = self.model(username=username, email=email, \*\*extra\_fields)
...
C:\Users\Administrator\PycharmProjects\untitled\venv\lib\site-packages\django\db\models\base.py
in__init__
raise TypeError("'%s' is an invalid keyword argument for this function" % kwarg)
...