get ip of user django code example
Example 1: how to get the user ip in djagno
def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
return ip
Example 2: how to get the user argent in django
request.META['HTTP_USER_AGENT']