OperationalError в джанго при работе с приложением для регистрации и аутентификации? Не работает переадресация
Создал отдельное приложение в джанго для работы с пользователями. Не могу подключить регистрацию и вход, что не так, выдаёт разные ошибки, где проблема с кодом?
users/forms.py
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import UserCreationForm
from django import forms
from django.utils.translation import gettext_lazy as _
User = get_user_model()
class UserCreationForm(UserCreationForm):
email = forms.EmailField(
label=_("Email"),
max_length=254,
widget=forms.EmailInput(attrs={'autocomplete': 'email'})
)
class Meta(UserCreationForm.Meta):
model = User
fields = ("username", "email")
users/models.py
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
users/urls.py
from django.urls import path, include
from .views import Register
urlpatterns = [
path('', include('django.contrib.auth.urls')),
path('register/', Register.as_view(), name='register'),
]
users/views.py
from django.contrib.auth import authenticate, login
from django.views import View
from django.shortcuts import render, redirect
from .forms import UserCreationForm
class Register(View):
template_name = 'registration/register.html'
def get(self, request):
context = {
'form': UserCreationForm()
}
return render(request, self.template_name, context)
def post(self, request):
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=password)
login(request, user)
return redirect('base')
context = {
'form': form
}
return render(request, self.template_name, context)
projectmanager/urls.py
from django.contrib import admin
from django.urls import path, include
from django.views.generic import TemplateView
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls')),
path('users/', include('users.urls'))
]