Installation¶
This app works with python 2.7, 3.4+, Django 1.10 and higher.
Recommended way to install is via pip:
pip install django-geoip
Basic¶
Add
django_geoip
toINSTALLED_APPS
in settings.py:INSTALLED_APPS = (... 'django_geoip', ... )
Create application tables in database:
python manage.py migrate
Obtain latest data to perform geoip detection by running management command:
python manage.py geoip_update
Advanced¶
In order to make user’s location detection automatic several other steps are required:
Add
LocationMiddleware
toMIDDLEWARE_CLASSES
:MIDDLEWARE = (... 'django_geoip.middleware.LocationMiddleware', ... )
Provide a custom location model (inherited from
django_geoip.models.GeoLocationFacade
)Specify this model in Settings:
GEOIP_LOCATION_MODEL = 'example.models.Location' # just an example, replace with your own
Include app urls into your urlconf if you want to allow visitors to change their location:
urlpatterns += [ ... url(r'^geoip/', include('django_geoip.urls')), ... ]
Add local ISO codes if you want to change or add countries in Settings:
GEOIP_CUSTOM_ISO_CODES = { "RU": "Российская Федерация", }