我正在尝试检索访问者的位置。成功检索 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 没有属性 GeoIP2”。
['HAS_GEOIP2', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']