Skip to content

Instantly share code, notes, and snippets.

@walison17
Created May 30, 2019 11:20
Show Gist options
  • Save walison17/1e6d6f27a8795b219bf078d7c84cade1 to your computer and use it in GitHub Desktop.
Save walison17/1e6d6f27a8795b219bf078d7c84cade1 to your computer and use it in GitHub Desktop.
def get_ip_from_request(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
return x_forwarded_for.split(',')[0]
return request.META.get('REMOTE_ADDR')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment