How do I get user IP address in django?

后端 未结 11 1132
野趣味
野趣味 2020-11-22 15:33

How do I get user\'s IP in django?

I have a view like this:

# Create your views
from django.contrib.gis.utils import GeoIP
from django.template impor         


        
11条回答
  •  北海茫月
    2020-11-22 16:30

    here is a short one liner to accomplish this:

    request.META.get('HTTP_X_FORWARDED_FOR', request.META.get('REMOTE_ADDR', '')).split(',')[0].strip()
    

提交回复
热议问题