GeoIP始终显示服务器的IP地址

时间:2013-04-30 12:53:50

标签: django nginx geoip

我正在尝试使用GeoIP,但是当我使用REMOTE_ADDR时遇到问题。显示的IP是我的服务器而不是客户端。

from django.contrib.gis.geoip import GeoIP
Example context:
    g = GeoIP()
    ip = self.request.META.get('REMOTE_ADDR')
    context['my_ip'] = ip # this display ip client
    context['pais_anuncio'] = g.country_code('ip') # this display ip my server.

我做错了什么,谢谢。

1 个答案:

答案 0 :(得分:0)

我的猜测是,因为您传递了字符串 'ip',所以它默认为您服务器的IP。尝试传递变量ip,如下所示:

context['pais_anuncio'] = g.country_code(ip)