I’m not being able to create users in my django application through the registration form that I created

I can create users through the manage.py shell, but not through the registration form, when I click the submit button, it just reloads the page and nothing else happens, also, my vs code is underscoring the create_user function in the line “user = Account.objects.create_user(…”, it says “Cannot access attribute “create_user” for class “BaseManager[Account]””

This is my forms.py:

from django import forms from .models import Account

class RegistrationForm(forms.ModelForm): password = forms.CharField(widget=forms.PasswordInput(attrs={ 'placeholder': 'Enter Password', })) ` confirm_password = forms.CharField(widget=forms.PasswordInput(attrs={ 'placeholder': 'Confirm Password', }))


email = forms.EmailField(
    max_length=255, help_text="Required. Add a valid email address.")

document = forms.CharField(widget=forms.TextInput(attrs={
    'placeholder': '(CPF/RG/PASSPORT)',
}), max_length=15, help_text="Enter a valid CPF, RG, or Passport.")

address = forms.CharField(widget=forms.TextInput(attrs={
    'placeholder': '1337 Example St, FL, US',
}), max_length=255, help_text="Enter your address.")

class Meta:
    model = Account
    fields = ['first_name', 'last_name',
              'username', 'phone_number', 'email', 'address', 'document', 'password']

def __init__(self, *args, **kwargs):
    super(RegistrationForm, self).__init__(*args, **kwargs)
    self.fields['phone_number'].widget.attrs['placeholder'] = '(xx) x xxxx-xxxx'
    for field in self.fields:
        self.fields[field].widget.attrs['class'] = 'form-control'`

This is my models.py

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

class MyAccountManager(BaseUserManager):

def create_user(self, first_name, last_name, document, phone_number, email, username, address=None, password=None, TCM_wallet=0):

    if not email:
        raise ValueError('User must have an email address.')
    if not username:
        raise ValueError('User must have a username.')
    if not document:
        raise ValueError('User must provide the document.')
    if not address:
        raise ValueError('User must provide the address.')

    user = self.model(
        email=self.normalize_email(email),
        username=username,
        first_name=first_name,
        last_name=last_name,
        phone_number=phone_number,
        document=document,
        address=address,
        TCM_wallet=TCM_wallet,
    )
    user.set_password(password)
    user.save(using=self._db)
    return user

def create_superuser(self, first_name, last_name, username, phone_number, document, email, password, address, TCM_wallet=0):
    user = self.create_user(
        email=self.normalize_email(email),
        username=username,
        first_name=first_name,
        last_name=last_name,
        document=document,
        phone_number=phone_number,
        address=address,
        password=password,
        TCM_wallet=TCM_wallet,
    )
    user.is_admin = True
    user.is_active = True
    user.is_staff = True
    user.is_superadmin = True
    user.save(using=self._db)
    return user

class Account(AbstractBaseUser):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
username = models.CharField(max_length=50, unique=True)
email = models.EmailField(max_length=100, unique=True) 
phone_number = models.CharField(max_length=50, blank=True) 
document = models.CharField( max_length=15, unique=True, help_text='Required. Enter a valid document (CPF, RG, or Passport).') 
address = models.CharField(max_length=100, blank=True, null=True) 
TCM_wallet = models.FloatField(default=0, editable=True)

# required fields
date_joined = models.DateTimeField(auto_now_add=True)
last_login = models.DateTimeField(auto_now=True)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
is_superadmin = models.BooleanField(default=False)

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username', 'first_name',
                   'last_name', 'document', 'address', 'phone_number',]

objects = MyAccountManager()

def __str__(self):
    return self.email

def has_perm(self, perm, obj=None):
    return self.is_admin

def has_module_perms(self, app_label):
    return True`

..and this is my views.py:

from django.shortcuts import render, redirect from .forms import RegistrationForm from .models import Account

def register(request): 
    if request.method == 'POST': form = RegistrationForm(request.POST)    
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            email = form.cleaned_data['email']
            phone_number = form.cleaned_data['phone_number']
            document = form.cleaned_data['document']
            address = form.cleaned_data['address']
            password = form.cleaned_data['password']
            username = email.split('@')[0]

            user = Account.objects.create_user(
                first_name=first_name,
                last_name=last_name,
                email=email,
                document=document,
                address=address,
                password=password,
                username=username,
            )

            user.phone_number = phone_number
            user.save()
    else:
        form = RegistrationForm()
    context = {
        'form': form,
    }
    return render(request, 'accounts/register.html', context)

def login(request): return render(request, 'accounts/login.html')

def logout(request): # assuming 'login' is the name of your login url pattern return redirect('login')`

Could someone please help me understanding this one? Thank you..

I expected that the info contained in the user registration form would be collected and saved as user.save().

New contributor

Clovis Aquino Borges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật