在Django上设置geoip时出错

我正在尝试使用GeoIP为网站添加地理位置。我按照Django文档上的说明进行操作,但是我收到了这个错误:
ImproperlyConfigured: Error importing middleware middleware: "cannot import name 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
    
已邀请:
似乎我得到了一个解决方案。 import语句应该是:
from django.contrib.gis.utils.geoip import GeoIP
    

要回复问题请先登录注册