Skip to content

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

@nueverest

Description

@nueverest

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions