Hi, I’m still very new to Python and Django. I am trying to create a working registration page and i get this error when submitting the form. I can’t find this error when looking on stack overflow or the forum and don’t know how to fix this issue. I copied the views and models code here. Any help is appreciated
views.py
from django.shortcuts import render, redirect
from django.contrib.auth import login as authlogin, logout, authenticate
from .forms import RegistrationForm
# Create your views here.
def login(request):
return render(request, "registration/login.html")
def signup(request):
if request.method == "POST":
form = RegistrationForm(request.POST)
if form.is_valid():
user = form.save
authlogin(request, user)
return redirect("/meaiapp/dashboard")
else:
form = RegistrationForm()
return render(request, "registration/signup.html", {"form": form})
models.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager
from django.utils import timezone
# Create your models here.
class CustomUserManager(UserManager):
def _create_user(self, email, password, **extra_fields):
if not email:
raise ValueError("You have not provided a valid e-mail address")
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self.db)
return user
def create_user(self, email=None, password=None, **extra_fields):
extra_fields.setdefault("is_staff", False)
extra_fields.setdefault("is_superuser", False)
return self._create_user(email, password, **extra_fields)
def create_superuser(self, email=None, password=None, **extra_fields):
extra_fields.setdefault("is_staff", True)
extra_fields.setdefault("is_superuser", True)
return self._create_user(email, password, **extra_fields)
class UserProfile(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(blank=True, default="", unique=True)
first_name = models.CharField(max_length=40, blank=True, default="")
last_name = models.CharField(max_length=40, blank=True, default="")
is_active = models.BooleanField(default=True)
is_superuser = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
date_joined = models.DateTimeField(default=timezone.now)
objects = CustomUserManager()
USERNAME_FIELD = "email"
EMAIL_FIELD = "email"
REQUIRED_FIELDS = ["first_name", "last_name"]
class Meta:
verbose_name = "User"
verbose_name_plural = "Users"
def get_full_name(self):
return self.first_name + " " + self.last_name
def get_short_name(self):
return self.first_name```