How do I get user IP address in django?

后端 未结 11 1399
野趣味
野趣味 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:09

    The simpliest solution (in case you are using fastcgi+nignx) is what itgorilla commented:

    Thank you for this great question. My fastcgi was not passing the REMOTE_ADDR meta key. I added the line below in the nginx.conf and fixed the problem: fastcgi_param REMOTE_ADDR $remote_addr; – itgorilla

    Ps: I added this answer just to make his solution more visible.

提交回复
热议问题