Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am using the latest version of django and python 3, When I log in I get the below error message.
django login() takes 1 positional argument but 2 were given
Please find the code for my login view below.
from django.shortcuts import render, get_object_or_404,redirect
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login
from authentication.forms import LoginForm, ForgottenPasswordForm, ResetPasswordForm
from authentication.functions import send_user_reset_password_link, resend_password_reset_link
from authentication.models import ResetPassword
# Create your views here.
def login(request):
error_message = None
heading = 'Login Form'
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
remember_me = form.cleaned_data['remember_me']
user = authenticate(request,username=username, password=password)
if not request.POST.get('remember_me', None):
#request.session.set_expiry(0)
if user is not None:
login(request, user)
return redirect('property_index',user.id)
# A backend authenticated the credentials
else:
error_message = 'No login credentials found'
# No backend authenticated the credentials
form = LoginForm()
return render(request,'authentication/forms/login.html',{
'form':form,
'error_message':error_message,
'heading':heading
The trouble is: you override the original django login function. So you should change import.
from django.contrib.auth import authenticate, login as dj_login
# ^^^^^^^^
and use
dj_login(request, user)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.