Skip to main content

Install

pip install django-geoip-utils==0.0.2

In your settings write:

import geoip_utils
GEOIP_PATH = geoip_utils.where()

This product includes GeoLite data created by MaxMind, available from http://maxmind.com/

Settings

GEOIP_REQUEST_IP_RESOLVER

Default:

geoip_utils.core.remote_addr_ip

The function used for getting the IP of the client from the request.

Options:

  • geoip_utils.utils.remote_addr_ip uses the REMOTE_ADDR of the request. Good for development and standard setup

  • geoip_utils.utils.x_forwarded_ip picks the first IP of HTTP_X_FORWARDED_FOR. This is useful for Load balancers, but could be spoofed in some cases. Amazon ELB set this reliably though

  • geoip_utils.utils.real_ip uses the HTTP_X_REAL_IP attribute

GEOIP_CACHE_METHOD

Default:

GEOIP_MEMORY_CACHE

The caching function used for retrieving the location.

Utils

There are a few server utility functions to make the handling easier:

from geoip_utils import core
core.get_country(request)
core.get_city(request)
core.get_lat_lon(request)
core.get_country_code(request)
core.get_country_name(request)

Filters

There are filters for extracting the information you need in the templates. You need to have django.core.context_processors.request enabled in your TEMPLATE_CONTEXT_PROCESSORS:

{% load geoip_tags %}
{{ request|country_code_of_request }}
{{ request|city_name_of_request }}
{{ request|postal_code_of_request }}
{{ request|region_of_request }}
{{ request|dma_code_of_request }}
{{ request|area_code_of_request }}
{{ request|lat_of_request }}
{{ request|lon_of_request }}

Todo

  • Add a management command to update the database files

Download files

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

Source Distribution

django-geoip-utils-0.0.4.tar.gz (19.0 MB view details)

Uploaded Source

File details

Details for the file django-geoip-utils-0.0.4.tar.gz.

File metadata

File hashes

Hashes for django-geoip-utils-0.0.4.tar.gz
Algorithm Hash digest
SHA256 784db574ae3c5882cfdefdffa125b70a92cc7835545358f201136bb454340028
MD5 8edd2ec9c7e41d503e77021bccc2c0e6
BLAKE2b-256 cbe0d9ff6fc9069b51ff6021220cc4583a37180e5af10b5d7644b05f8fa4eea6

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

1 file

0.1

1 file

0.0.6

1 file

0.0.5

1 file

This release

0.0.4 This release

1 file

0.0.3

1 file

0.0.2

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page