Skip to content

Instantly share code, notes, and snippets.

@pradumangoyal
Last active December 9, 2018 15:22
Show Gist options
  • Save pradumangoyal/e798a508009c982f29a839b3e918a667 to your computer and use it in GitHub Desktop.
Save pradumangoyal/e798a508009c982f29a839b3e918a667 to your computer and use it in GitHub Desktop.
# method to get the client IP address
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment