【发布时间】:2019-10-23 20:50:12
【问题描述】:
我正在尝试检索访问者的位置。 成功检索到我要使用的 IP 地址后 GeoIP2 对象以获取有关位置的信息。 https://docs.djangoproject.com/en/2.2/ref/contrib/gis/geoip2/#django.contrib.gis.geoip2.GeoIP2
在我的 settings.py 文件中,我将“django.contrib.gis.geoip2”添加到我安装的应用程序中:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis.geoip2',
'web'
]
使用 shell 一切正常 [python3 manage.py shell]:
目录(django.contrib.gis.geoip2)
['GeoIP2', 'GeoIP2Exception', 'HAS_GEOIP2', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'base', 'geoip2', 'resources']
但是尝试在我的应用程序“web”中使用 GeoIP2 对象时出现错误:“django.contrib.gis.geoip2 has no attribute GeoIP2”。
['HAS_GEOIP2', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
【问题讨论】:
标签: django python-3.x geoip2