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)

 

message profile
Admin
2022-05-24

 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

Click on the button below to add a new message to this thread

Tags

Thread detail

Satus: Open
Messages: 1Started: 2022-05-24
loading..

DEVMAESTERS

Newsletter

Services

Frontend Development |Backend Development |Full Website Development |Bootstrap Website upgrades | Website Debbugging | Website Hosting & deployment

Contact

Interested in hiring me or collaborating with me on a project, click on any of the links below to get my social media handle

Or contact me via Tel: (+234)-806-225-7480 | Email: abubakarzakari1703@gmail.com

Copywright@devmaesters.com
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.