我想找回访客的位置。在成功检索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'
]使用外壳,一切都工作得很完美,python3 manage.py shell
dir(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__']发布于 2019-06-09 04:24:33
在链接到的文档中提到了一个依赖项,您在web服务器上缺少了这个依赖项:
为了执行基于IP的地理定位,GeoIP2对象需要geoip2 Python库。
您需要用pip install geoip2来安装它。
请注意,文档还提到了使用此模块时还需要设置的其他要求。
https://stackoverflow.com/questions/56509687
复制相似问题