AttributeError at /auth/users/

243 views
Skip to first unread message

arun n

unread,
Jul 1, 2023, 1:14:53 PM7/1/23
to Django users
Hello, 

I am new to Django.  I am getting the below error. Can someone help.

from django.db import models
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager, UserManager


class UserAccountManager(BaseUserManager):
    def create_user(self, email, name, password=None):
        if not email:
            raise ValueError('Email address required')

        email = self.normalize_email(email)
        user = self.model(email=email, name=name)
        user.set_password(password)
        user.save()
        return user

AttributeError at /auth/users/'Manager' object has no attribute 'create_user'
Request Method:

POST

Request URL:

http://127.0.0.1:8000/auth/users/

Django Version:

4.2.2

Exception Type:

AttributeError

Exception Value:

'Manager' object has no attribute 'create_user'

Exception Location:

C:\Users\Arun\.virtualenvs\nc-backend-zDgCjJYE\Lib\site-packages\djoser\serializers.py, line 48, in perform_create

Raised during:

djoser.views.UserViewSet

Python Executable:

C:\Users\Arun\.virtualenvs\nc-backend-zDgCjJYE\Scripts\python.exe

Python Version:

3.11.4

Python Path:

['C:\\Users\\Arun\\Documents\\GitHub\\nc-backend', 'C:\\Users\\Arun\\AppData\\Local\\Programs\\Python\\Python311\\python311.zip', 'C:\\Users\\Arun\\AppData\\Local\\Programs\\Python\\Python311\\DLLs', 'C:\\Users\\Arun\\AppData\\Local\\Programs\\Python\\Python311\\Lib', 'C:\\Users\\Arun\\AppData\\Local\\Programs\\Python\\Python311', 'C:\\Users\\Arun\\.virtualenvs\\nc-backend-zDgCjJYE', 'C:\\Users\\Arun\\.virtualenvs\\nc-backend-zDgCjJYE\\Lib\\site-packages']

Server time:

Fri, 30 Jun 2023 18:48:41 +0000

Fikayo Soetan

unread,
Jul 1, 2023, 9:08:35 PM7/1/23
to Django users
Good day,
I'm also still learning but I think the name of the function should be "_create_user"
Fikayo.

Muhammad Juwaini Abdul Rahman

unread,
Jul 1, 2023, 9:10:58 PM7/1/23
to Django users
What's your code in urls.py for `/auth/user`?

s.alaoui youssef

unread,
Jul 2, 2023, 3:28:18 PM7/2/23
to Django users
class User(AbstractUser):
   
   .....

    objects = UserManager()

we have to create User class and specify as objects your UserManager

s.alaoui youssef

unread,
Jul 2, 2023, 3:28:18 PM7/2/23
to Django users
Hi
you have to create class User(AbstractUser) 

class User(AbstractUser):
   ...
    objects = UserManager()

and add objects with your UserManager

ivan harold

unread,
Aug 9, 2023, 11:52:06 AM8/9/23
to Django users
Is the issue already resolved?
Reply all
Reply to author
Forward
0 new messages