Skip to main content

Django hook (Middleware and Decorator) to geolocate visitors using their IP address

Project description

Django Ip Geolocation:

Django request/response hooks to geolocate visitors by their ip address

Usage:

Decorator:

Use decorators to decorate views :

from django_ip_geolocation.decorators import with_ip_geolocation

@with_ip_geolocation
def api_view(request):
   location = request.location
   ...

Middleware:

First you need to add the middleware into your settings.py

MIDDLEWARE = [
    ...
    'django_ip_geolocation.middleware.IpGeolocationMiddleware',
    ...
]

Then the location is available to all views in request and response:

def api_view(request):
   location = request.location
   ...
   
def other_view(request):
  location = request.location
  ...

Settings

You can configure backend for your hook in the settings.py as follow:

GEOLOCATION_BACKEND = 'django_ip_geolocation.backends.IPGeolocationAPI'

Available Backends:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-ip-geolocation-0.0.6.tar.gz (2.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page