display ip address of users, django code example
Example 1: get user ip address django
def visitor_ip_address(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: get ip address in django
request.META.get("REMOTE_ADDR")