""" use GeoIP to get the city/region information from the IP address if possible ***WARNING*** THE GeoIP module is 'GPL'. including this module in your code will make your codebase 'GPL' """ from django.conf import settings import GeoIP def get_geo(request): try: filename = settings.GEO_CITY_FILE except AttributeError: filename = "/magik/GeoIPCity.dat" try: gi = GeoIP.open(filename,GeoIP.GEOIP_STANDARD) except: return {} ip = request.META['REMOTE_ADDR'] if settings.DEBUG: ip = request.GET.get('IP',ip) try: gir = gi.record_by_addr(ip) except : # print "err" return {} # print ip # print gir if gir: gir['ip'] = ip print gir return gir else: return {}