'Python Django, How I Can use username(uname) or email as a login credentials?

Python Django, How I Can use username(uname) or email as a login credentials ? my python file are views,URLs,models,settings.py

def loginpage(request):

if request.method=="POST":
    try:
        Userdetails=newacc.objects.get(email=request.POST['email'],pwd=request.POST['pwd'])
        print("Username=",Userdetails)
        request.session[ 'email']=Userdetails.email
        return render(request,'Logout.html')
    except newacc.DoseNotExist as e:
        messages.success(request,' Username / Password Invalid.')
return render(request,'Login.html')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source