Skip to content

Instantly share code, notes, and snippets.

@Allwin12
Created September 4, 2020 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Allwin12/81d4e2ceadf773a1d02721e042ae8e5b to your computer and use it in GitHub Desktop.
Save Allwin12/81d4e2ceadf773a1d02721e042ae8e5b to your computer and use it in GitHub Desktop.
class SampleView(APIView):
def get(self, request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for
else:
ip = request.META.get('REMOTE_ADDR')
return Response({'ip_address': ip})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment