djangoipgeoip2

Getting errors in using GeoIP2 in django


I am trying to use GeoIP2 to get user's cities and countries using their IP when they view my website. I have downloaded 2 files from https://dev.maxmind.com/geoip/legacy/geolite/ , GeoLite Country and GeoLite City Binary/gzip files. After that I put them in the directory geoip inside my projects root. And there I unzipped them. Here is the image and I have also added this line to my project settings.py file: GEOIP_PATH = os.path.join(BASE_DIR, 'geoip') but when I try to use GeoIP2 it gives me error:

GeoIP2Exception at /

Invalid GeoIP country and city data files.

I am using django 2.0.4.

can anybody help me to solve this?

thanks.


Solution

  • You need to use GEOIP2 files : https://dev.maxmind.com/geoip/geoip2/geolite2/

    The extension is .mmdb, the .dat format is for old GEOIP and django use GEOIP2