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
def login(request):
if request.method == "POST":
form = AuthenticationForm(data=request.POST)
if form.is_valid():
user=form.get_user()
login(request,user)
if 'next' in request.POST:
return HttpResponseRedirect(reverse(request.POST.get('next')))
else:
return HttpResponseRedirect(reverse('website:books'))
else:
return render(request,'website/login.html')
else:
form=AuthenticationForm()
return render(request,'website/login.html',{'form':form})
The error i am getting is:
File "D:\playground\blog\website\views.py", line 16, in login
login(request,user)
TypeError: login() takes 1 positional argument but 2 were given
[10/Mar/2020 14:34:57] "POST /website/login/ HTTP/1.1" 500 74342
What am i missing?
The problem is that your custom function is called "login" and then you are trying to call the django function from django.contrib.auth
which is also called login
.
Look on that line and you call login(request,user)
So the fix is one of these
Rename your view to something other than login
In the import use "as" to alias the existing function to something else. E.G. from django.contrib.auth import login as django_login
then change login(request,user)
for django_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.