django-pageviews icon indicating copy to clipboard operation
django-pageviews copied to clipboard

Store the IP Address (if available) for the User with django-ipware

Open nueverest opened this issue 10 years ago • 0 comments

It is straightforward to log a users IP Address with django-ipware: https://github.com/un33k/django-ipware/blob/master/ipware/utils.py It supports both IPv4 and IPv6 as well as Python 3.

Install: pip install django-ipware In your view or middleware:

from ipware.ip import get_ip
ip = get_ip(request)
if ip is not None:
    print "we have an IP address for user"
else:
    print "we don't have an IP address for user"

It will make the best attempt to get the user's IP address or returns None to indicate that it could not determine the user's IP address.

nueverest avatar Sep 29 '14 13:09 nueverest