3
我正在嘗試使用GeoIP將地理位置添加到網站。我按照Django docs上的說明操作,但出現此錯誤:ImproperlyConfigured: Error importing middleware middleware: "cannot import name GeoIP"
可能缺少什麼?我已經添加了地理定位功能作爲一個自定義中間件如下:在Django上設置geoip時出錯
from django.contrib.gis.utils import GeoIP
class LocationMiddleware(object):
def process_request(self, request):
g = GeoIP()
ip = request.META.get('REMOTE_ADDR', None)
if (not ip or ip == '127.0.0.1') and
request.META.has_key('HTTP_X_FORWARDED_FOR'):
ip = request.META['HTTP_X_FORWARDED_FOR']
if ip:
city = g.city(ip)['city']
else:
# set default city
return city