arik
arik

Reputation: 71

get the host the user is coming from

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.

Upvotes: 0

Views: 218

Answers (1)

Chris B.
Chris B.

Reputation: 90329

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.

Upvotes: 1

Related Questions