python - Django : Get user IP from development server -
i'm trying put user ip in page send user. i've tried explained here.
so view looks :
def yourip(request): return httpresponse("your ip : %s" % request.meta.get('http_x_forwarded_for'))
but request.meta.get('http_x_forwarded_for')
returns none
. possible development server? or problem elsewhere?
thank you.
try this:
def get_client_ip(request): x_forwarded_for = request.meta.get('http_x_forwarded_for') if x_forwarded_for: print "returning forwarded_for" ip = x_forwarded_for.split(',')[-1].strip() elif request.meta.get('http_x_real_ip'): print "returning real_ip" ip = request.meta.get('http_x_real_ip') else: print "returning remote_addr" ip = request.meta.get('remote_addr') return ip
Comments
Post a Comment