После регистрации нового пользователя он не появляется в списке юзеров, но в админке появляется красная надпись "Ошибка"
models.py
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
wishlist = models.ForeignKey('Product', on_delete=models.CASCADE, null=True)
def __str__(self):
return f'{self.user.username} Profile'
views.py
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserRegisterForm
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
def user_register(request):
if request.method == 'POST':
form = UserRegisterForm(request.POST)
if form.is_valid():
form.save
username = form.cleaned_data.get('username')
messages.success(request, 'Вы успешно зарегестрировались!')
return redirect('login')
else:
messages.error(request, 'Ошибка')
print('Выдает ошибку')
else:
form = UserRegisterForm()
return render(request, 'register.html', {'form': form})
print('Выдает ошибку')
forms.py
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from django.core.files.images import get_image_dimensions
from .models import Profile
from django.forms import ModelForm
class UserRegisterForm(UserCreationForm):
email = forms.EmailField()
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']