问题
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