get city not country list
This commit is contained in:
parent
6217fb774f
commit
5cde8977ef
2 changed files with 13 additions and 7 deletions
|
|
@ -17,15 +17,22 @@ def get_location(ip):
|
|||
country = city = None
|
||||
try:
|
||||
g = GeoIP2()
|
||||
location = g.city(ip)
|
||||
except:
|
||||
country = city = None
|
||||
else:
|
||||
try:
|
||||
location = g.city(ip)
|
||||
except django.contrib.gis.geoip2.GeoIP2Exception:
|
||||
try:
|
||||
location = g.country(s.ip)
|
||||
except:
|
||||
location = None
|
||||
if location:
|
||||
country = ox.get_country_name(location['country_code'])
|
||||
if location['city']:
|
||||
if location.get('city'):
|
||||
city = location['city']
|
||||
if isinstance(city, bytes):
|
||||
city = city.decode('latin-1')
|
||||
except:
|
||||
country = city = None
|
||||
return city, country
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue