【发布时间】:2012-10-31 23:47:54
【问题描述】:
我从浏览器收到“无法导入名称 GeoIP”错误,但在 python 终端上没有。例如 /tmp/geo 中的地理数据。以下在 python 终端中工作。
from django.contrib.gis.geoip import GeoIP
GeoIP(path='/tmp/geo/')
但是 django 视图中的以下内容给出了错误
from django.contrib.gis.geoip import GeoIP
return HttpResponse (GeoIP(path='/tmp/geo/'))
任何指针都会有所帮助。我正在使用 django 1.4,python 2.6。这是痕迹。谢谢。
Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
300. sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
209. return ResolverMatch(self.callback, args, kwargs, self.name)
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in callback
216. self._callback = get_callable(self._callback_str)
File "/usr/lib/python2.6/site-packages/django/utils/functional.py" in wrapper
27. result = func(*args)
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py" in get_callable
92. lookup_view = getattr(import_module(mod_name), func_name)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/x/y/z/views.py" in <module>
12. from django.contrib.gis.utils import GeoIP
Exception Type: ImportError at /
Exception Value: cannot import name GeoIP
【问题讨论】:
-
试过“from django.contrib.gis.utils.geoip import GeoIP”也不行
-
@NathanVillaescusa 我认为这不再适用于 django 1.4