可能重复: 在Django上设置geoip错误
我从浏览器中得到“无法导入名称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发布于 2012-10-31 23:56:16
这两条语句似乎不同(看看堆栈跟踪):
from django.contrib.gis.utils import GeoIPvs
from django.contrib.gis.geoip import GeoIP看看来源,GeoIP在django.contrib.gis.geoip.base中定义,在django.contrib.gis.geoip中导入,这解释了为什么它在控制台中工作,而不是在您使用django.contrib.gis.utils.GeoIP的视图中。
因此,您应该在任何地方使用from django.contrib.gis.geoip import GeoIP。
您的问题可能来自于django.contrib.gis.utils模块是在Django移走1.4这一事实。
https://stackoverflow.com/questions/13169040
复制相似问题