python - Using django GeoIP and MaxMind database -


i'm trying setup geoip in django identify source of connection (to tailor content different countries) running problem.

first execute:

from django.contrib.gis import geoip geo = geoip.geoip('path maxmind db') 

then geo.country('www.google.com') returns you'd expect. other popular websites work fine.

however when try on own client ip empty record. example: geo.country('127.6.89.129')

returns {'country_name': none, 'country': none}

what missing here? maxmind database cover popular sites can't used if want identify source of connection?

i'm using browser locale settings identify language unfortunately need geo-location tailor of content independently of language.

your ip forwarded

def foo(request):       g = geoip()     country = g.country(get_client_ip(request))     country_code = country['country_code']   def get_client_ip(request):     x_forwarded_for = request.meta.get('http_x_forwarded_for')     if x_forwarded_for:         ip = x_forwarded_for.split(',')[0]     else:         ip = request.meta.get('remote_addr')     return ip 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -