TypeError at /signup 'NoneType' object is not callable in Django

倖福魔咒の 提交于 2019-12-11 17:20:05

问题


Have custom User model, but using this model I can only create superuser using terminal command "python manage.py createsuperuser".

The error : "TypeError at /signup 'NoneType' object is not callable"

Traceback: 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", {})

回答1:


Change these these two codes in views.py

userV= userM.create_user(int(Mno),Role,Pass)


userV= userM.create_staffuser(int(Mno),Role,Pass)

to

userV= Users.object.create_user(int(Mno),Role,Pass)

userV= Users.object.create_staffuser(int(Mno),Role,Pass)

We must reference Users model, where it is linked with UserManger.



来源:https://stackoverflow.com/questions/55286352/typeerror-at-signup-nonetype-object-is-not-callable-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!