def get_client_ip(request):
    """
    Get the client IP address from the *request* object.

    Looks up the IP address that sent the *request* by checking the
    `HTTP_X_FORWARDED_FOR` header or `REMOTE_ADDR` in the request's metadata.

    Args:
        request: a Django request.

    Returns:
        An IP address as a string or an empty string if no IP could be found.
    """
    client_ip = request.META.get("HTTP_X_FORWARDED_FOR", '')

    try:
        # X_FORWARDED_FOR returns client1, proxy1, proxy2,...
        client_ip = client_ip.split(',')[0]
    except IndexError:
        pass

    if not client_ip:
        client_ip = request.META.get('REMOTE_ADDR', '')

    return client_ip.strip()