get the host the user is coming from

225 Views Asked by At

i wanted to know in python how can i get the host the user came from? how do i extract it?

i tried this:

host = self.request._environ['HTTP_HOST']

but it's empty...

Do you have any idea what it should be

Thanks.

1

There are 1 best solutions below

2
On

self.request._environ['HTTP_HOST'] tells you your host name.

You can use self.request.remote_addr to get the remote IP address. You'll need to do a reverse DNS lookup (which might fail) if you need a host name from that.