REMOTE_ADDR的属性request.META。检查此帖子以获取有关远程地址的完整解决方案。注册时,您可以执行以下操作:addr = request.META.get('REMOTE_ADDR', None)并保存此IP地址。现在,您可以使用以下方式获取城市GeoIP:from django.contrib.gis.utils import GeoIPg = GeoIP()addr = request.META.get('REMOTE_ADDR', None) #Or retrive this from the userprofile you saved while registeringcity = 'New York' #Or any default cityif addr: city = g.city(addr)['city']