ModuleNotFoundError at /accounts/login/ No module named 'allauth.forms'
Я пытаюсь добавить allauth login и signup в свой проект и получаю эту ошибку
*ModuleNotFoundError at /accounts/login/*
* Отсутствует модуль с именем 'allauth.forms'*
Это обратная связь
`
`
вот полные коды
*forms.py*
`
from allauth.account.forms import LoginForm,SignupForm
from django import forms
class CustomLoginForm(LoginForm):
username = forms.CharField(max_length=30, required=False)
def __init__(self, *args, **kwargs):
super(CustomLoginForm, self).__init__(*args, **kwargs)
# Customize the form initialization if needed
def clean_custom_field(self):
username = self.cleaned_data.get('username')
# Add custom validation for the field if needed
return username
def login(self, *args, **kwargs):
# Perform the login and any additional actions
return super(CustomLoginForm, self).login(*args, **kwargs)
class CustomSignUpForm(SignupForm):
username = forms.CharField(max_length=30,required=True)
def save(self, request):
user = super(CustomSignUpForm, self).save(request)
user.username = self.cleaned_data['username']
user.save()
return user
`
*project urls.py*
Я сделал отдельное приложение под названием accounts для всего процесса авторизации
`
from django.contrib import admin
from django.urls import path,include
from django.views.generic import TemplateView
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('consultation.urls')),
path('accounts/',include('allauth.urls')),
path('accounts/',include('accounts.urls')),
path('dashboard',include('dashboard.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
`
*app urls.py*
`
"""
URL configuration for Hospital_Management project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import path
from .views import CustomSignUpView,CustomLoginView
app_name ='user'
urlpatterns = [
path('signup/',CustomSignUpView.as_view(),name='account_signup'),
path('login/', CustomLoginView.as_view(), name='account_login'),
]
`
*views.py*
`
from django.shortcuts import render
from allauth.account.views import LoginView,SignupView
from .forms import CustomSignUpForm, CustomLoginForm
# Create your views here.
class CustomSignUpView(SignupView):
form_class = CustomSignUpForm
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['username'] = CustomSignUpForm.username
return context
def form_valid(self, form):
response = super().form_valid(form)
# Add any custom behavior after the form is valid
return response
class CustomLoginView(LoginView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['username'] = CustomLoginForm.username # Add any extra context you need
return context
def form_valid(self, form):
response = super().form_valid(form)
# Add any custom behavior after the form is valid
return response
`
Я скопировал эту форму в чат gpt, так как документация по allauth запутана, пожалуйста, просмотрите ее и помогите мне, что не так с кодом