def is_loopback_connection(request):
 host_ip = socket.gethostbyname(socket.gethostname())
 remote_ip = get_request_ip(request)
 return (remote_ip in ['127.0.0.1', 'localhost', host_ip])

def is_loopback_connection ( request ) : host_ip = socket . gethostbyname ( socket . gethostname ( ) ) remote_ip = get_request_ip ( request ) return ( remote_ip in [ '127.0.0.1' , 'localhost' , host_ip ] )
test whether the ip making the request is the same as the ip serving the request .