具有自定义用户模型,但是使用此模型,我只能使用终端命令“ python manage.py createsuperuser”创建超级用户。
错误:“ / signup'NoneType'对象处的TypeError不可调用”
跟踪: 1
userV= userM.create_user(int(Mno),Role,Pass)
2
mobile_no=mobile_no,
models.py
class Users(AbstractBaseUser, PermissionsMixin):
object = UserManager()
mobile_no = models.IntegerField(_('MobNumber'), null=True, blank=True,unique=True)
role = models.CharField(_('Role'), max_length=70, null=True, blank=True)
activated = models.BooleanField(_('Activated'), default=False)
is_admin = models.BooleanField(_('is_admin'), default=False)
is_staff = models.BooleanField(_('is_staff'), default=False)
views.py
def Sign_up(request):
Fname = request.POST.get("first_name")
Lname = request.POST.get("last_name")
Mno = request.POST.get("Mobile")
email = request.POST.get("email")
Pass = request.POST.get("pass")
Role = request.POST.get("role")
Loc = request.POST.get("self_loc")
if request.method == "POST":
userM = UserManager()
if Role=="Consumer":
userV= userM.create_user(int(Mno),Role,Pass)
else:
userV= userM.create_staffuser(int(Mno),Role,Pass)
userV.first_name=Fname
userV.last_name=Lname
userV.email=email
userV.location=Loc
return render(request, "home.html", {})
else:
return render(request, "registration/signup.html", {})
答案 0 :(得分:0)
在views.py
中更改这两个代码userV= userM.create_user(int(Mno),Role,Pass)
userV= userM.create_staffuser(int(Mno),Role,Pass)
到
userV= Users.object.create_user(int(Mno),Role,Pass)
userV= Users.object.create_staffuser(int(Mno),Role,Pass)
我们必须引用与UserManger链接的“用户”模型。