def ip_for_request(request):
 meta = request.META
 return meta.get(u'HTTP_X_FORWARDED_FOR', meta[u'REMOTE_ADDR']).split(u',')[0]

def ip_for_request ( request ) : meta = request . META return meta . get ( u'HTTP_X_FORWARDED_FOR' , meta [ u'REMOTE_ADDR' ] ) . split ( u',' ) [ 0 ]
returns ip address for request - first checks http_x_forwarded_for header .