Created
September 4, 2020 14:36
-
-
Save Allwin12/81d4e2ceadf773a1d02721e042ae8e5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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