AttributeError error code example

Example 1: attributeerror:

# user in the login should be a User Object not the username.

from django.contrib.auth.models import User

def get_django_user_by_username(username):
    """Get the django user
    Args:
        username (str): email id of the user
    Returns:
        object: django user object
    """
    return User.objects.filter(username=username).first()

user = get_django_user_by_username(email)

login(request, user, backend="django.contrib.auth.backends.ModelBackend")

Example 2: attributeerror:

AttributeError: can be defined as an error that is raised when an attribute 
 reference or assignment fails.