블로그 이미지
흰색앵초

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2013. 2. 26. 19:27 프로그래밍/장고
views.py에서 아래와 같이 사용하면 된다. 원하는대로 약간씩 고쳐서 쓰면 무방할 듯
def get_client_ip(request):
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[0]
    else:
        ip = request.META.get('REMOTE_ADDR')
    return ip

출처 : http://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django


posted by 흰색앵초