Giter Club home page Giter Club logo

django-geoip-utils's Introduction

GeoIp Data and helpers

Installation

pip install django-geoip-utils

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 the HTTP_X_FORWARDED_FOR request header. This is useful for Load balancers, but could be spoofed in some cases. Amazon ELB sets this reliably though.

  • 'geoip_utils.utils.real_ip'

    Uses the HTTP_X_REAL_IP attribute

GEOIP_CACHE_METHOD

Default

django.contrib.gis.geoip.GeoIP.GEOIP_STANDARD

The caching function used for retrieving the location.

Options
  • django.contrib.gis.geoip.GeoIP.GEOIP_STANDARD

    Read database from filesystem, uses least memory

  • django.contrib.gis.geoip.GeoIP.GEOIP_MEMORY_CACHE

    Load database into memory, faster performance but uses more memory

  • django.contrib.gis.geoip.GeoIP.GEOIP_CHECK_CACHE

    check for updated database. If database has been updated, reload filehandle and/or memory cache. This option is not thread safe but is good for development.

  • django.contrib.gis.geoip.GeoIP.GEOIP_INDEX_CACHE

    Just cache the most frequently accessed index portion of the database, resulting in faster lookups than GEOIP_STANDARD, but less memory usage than GEOIP_MEMORY_CACHE - useful for larger databases such as GeoIP Organization and GeoIP City. Note, for GeoIP Country, Region and Netspeed databases, GEOIP_INDEX_CACHE is equivalent to GEOIP_MEMORY_CACHE.

  • django.contrib.gis.geoip.GeoIP.GEOIP_MMAP_CACHE

    Loads database into mmap shared memory (not available on Windows).

Utilities

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

from geoip_utils import core as geoip

geoip.get_country(request)

geoip.get_city(request)

geoip.get_lat_lon(request)

geoip.get_country_code(request)

geoip.get_country_name(request)

Template 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 }}

Management command

You can run the update_geoip_data management command to download updated GeoIP data in place.

django-geoip-utils's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.