(request: HttpRequest)
return request._cached_user
Get a `User` from the request. If the user cannot be found we return `AnonymousUser`.

    Modified from: https://github.com/django/django/blob/6e99585c19290fb9bec502cac8210041fdb28484/django/contrib/auth/middleware.py#L9-L12
Get a `User` from the request. If the user cannot be found we return `AnonymousUser`.
Get a User from the request . If the user cannot be found we return AnonymousUser .
def get_user(request: HttpRequest) -> User:
    """
    Get a `User` from the request. If the user cannot be found we return `AnonymousUser`.

    Modified from: https://github.com/django/django/blob/6e99585c19290fb9bec502cac8210041fdb28484/django/contrib/auth/middleware.py#L9-L12
    """
    if not hasattr(request, "_cached_user"):
        user = None
        try:
            user_id = request.session["user_id"]
        except KeyError:
            pass
        else:
            user = User.objects.filter(id=user_id).first()
        request._cached_user = user or AnonymousUser()  # type: ignore [attr-defined]
    return request._cached_user
def get_user ( request : HttpRequest ) -> User : if not hasattr ( request , "_cached_user" ) : user = None try : user_id = request . session [ "user_id" ] except KeyError : pass else : user = User . objects . filter ( id = user_id ) . first ( ) request . _cached_user = user or AnonymousUser ( ) # type: ignore [attr-defined] return request . _cached_user