There were a couple of other similar questions with answer but none of them fixed my problem. I am getting 'You have multiple authentication backends configured and therefore must provide the backend
argument or set the backend
attribute on the user' every time I try to create a new user using by sign up in Django. Here is my view:
def signupUser(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
form.save(commit=False)
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=raw_password)
form.save()
user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, user)
return redirect('home')
else:
form = SignUpForm()
return render(request, 'signup.html', {'form': form})
I had added user.backend = 'django.contrib.auth.backends.ModelBackend'
in hopes of fixing the problem, but it did nothing.
My forms.py:
class SignUpForm(UserCreationForm):
email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
password1=forms.CharField(help_text='Your password cant be too similar to your other personal information. Your password must contain at least 8 characters. Your password cant be a commonly used password. Your password cant be entirely numeric.', widget=forms.PasswordInput)
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']
By the way, in my AUTHENTICATION_BACKENDS are 'django.contrib.auth.backends.ModelBackend' and 'allauth.account.auth_backends.AuthenticationBackend',