By Stephen

2011-02-04 10:34:30 8 Comments

I'm trying to add geolocation to a website, using GeoIP. I followed the instructions on Django docs, but I get this error: ImproperlyConfigured: Error importing middleware middleware: "cannot import name GeoIP" What can be missing? I've added the geolocation function as a custom middleware as below:

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 == '') and 
            ip = request.META['HTTP_X_FORWARDED_FOR']
        if ip:
           city =['city']
           # set default city

    return city


@Stephen 2011-02-04 11:56:05

Seems I got a solution after all. The import statement should be:

from django.contrib.gis.utils.geoip import GeoIP

Related Questions

Sponsored Content

12 Answered Questions

[SOLVED] differentiate null=True, blank=True in django

29 Answered Questions

[SOLVED] Does Django scale?

23 Answered Questions

[SOLVED] Django - Set Up A Scheduled Job?

10 Answered Questions

[SOLVED] Need a minimal Django file upload example

  • 2011-05-03 15:17:05
  • qliq
  • 272427 View
  • 626 Score
  • 10 Answer
  • Tags:   django file upload

1 Answered Questions

[SOLVED] Django 1.11 TypeError at / context must be a dict rather than unicode

2 Answered Questions

[SOLVED] Python/django : Cannot import GeoIP

1 Answered Questions

[SOLVED] Django Admin Kink with Collapse Fieldsets

1 Answered Questions

[SOLVED] Django process_response() takes 2 positional arguments but 3 were given

2 Answered Questions

2 Answered Questions

[SOLVED] Django: What's the correct way to get the requesting IP address?

  • 2010-05-15 13:46:03
  • FunLovinCoder
  • 589 View
  • 0 Score
  • 2 Answer
  • Tags:   python django

Sponsored Content