-1

I am building an application in Django that gets the ip address of the user to track their location. And once their location is determined, I want to be able to figure if their signup date coincides with a holiday in their country.

How can I do this?

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
  • Does this answer your question? [How do I get user IP address in Django?](https://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django) – jnns Jun 13 '23 at 08:07

1 Answers1

0

Client IP is send to your Django application from your web server (Nginx for example) you can access it in request like this:

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
Mojtaba
  • 583
  • 1
  • 5
  • 15