Skip to content

Instantly share code, notes, and snippets.

@ionatan-israel
Created September 8, 2016 14:50
Show Gist options
  • Save ionatan-israel/0121f0bb6818dab92fe7a8c3d4623fa1 to your computer and use it in GitHub Desktop.
Save ionatan-israel/0121f0bb6818dab92fe7a8c3d4623fa1 to your computer and use it in GitHub Desktop.
Ip Address from request Django
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ipaddress = x_forwarded_for.split(',')[-1].strip()
else:
ipaddress = request.META.get('REMOTE_ADDR')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment