how to get the user ip in djagno

Solutions on MaxInterview for how to get the user ip in djagno by the best coders in the world

showing results for - "how to get the user ip in djagno"
María Fernanda
10 Apr 2017
1def get_client_ip(request):
2    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
3    if x_forwarded_for:
4        ip = x_forwarded_for.split(',')[0]
5    else:
6        ip = request.META.get('REMOTE_ADDR')
7    return ip