Я получаю, что объект 'AnonymousUser' не имеет атрибута '_meta', ошибка при использовании get_user_model. Вот мои form.py и файлы просмотра:
это файл forms.py
class LoginForm(forms.Form):
username = forms.CharField()
password = forms.CharField(widget=forms.PasswordInput())
def clean_username(self):
username = self.cleaned_data.get('username')
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise forms.ValidationError('Are you sure you are registered? we can not find this user.')
return username
def clean_password(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')
try:
user = User.objects.get(username=username)
except:
user = None
if user is not None and not user.check_password(password):
raise forms.ValidationError('Invalid password')
elif user is None:
pass
else:
password
это файл views.py
def login_view(request):
form = LoginForm(request.POST or None)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user = authenticate(username=username, password=password)
login(request, user)
context = {
'form':form
}
return render(request, 'form.html', context)