Django valueError at /login/
I am trying to implement a signup page for my django project but after the data gets passed from the login template to my loginPage view it outputs the error below
You have multiple authentication backends configured and therefore must provide the `backend` argument or set the `backend` attribute on the user.
Below is the code for my login page view
def loginpage(request):
if request.user.is_authenticated:
return redirect('home')
form = Login_form
if request.method == "POST":
email=request.POST.get('email')
password=request.POST.get('password')
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('home')
else:
messages.info(request, 'Email OR Password is incorrect')
context = {}
return render(request, 'login.html', context)
This error occurs because you have set more than one authentication backend in your projects settings.py and django doesn't know the specific one you want to use for this particular authenticaton process.
I had this same error when I attempted to implement social authentication like google and facebook in my website. My authentication backend in settings.py looked like this
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend'
]
A quick fix is to simply specify the backend you want to use in your loginpage view.
For example lets say you wish to use django's default authentication backend then simply change the code below.
login(request, user)
to
login(request, user, backend = 'django.contrib.auth.backends.ModelBackend')
Add Message
Tags
Thread detail
Thread Create
Privacy Policy
By using our website,
you agree that devmaesters can store cookies on your device and disclose information in accordance with our privacy policy.