Forums

Differentiating between http_host on my local computer, and in bash console on Pythonanywhere

Im am currently using web2py's request.env.http_host value to differentiate between my developement environment, and my live site.

However, when I run my app in the bash console on Pythonanywhere, the request.env.http_host value is 127.0.0.1:8000, which is the same as my development computer. Is there anyway to differentiate between the http_host in the bash console on Pythonanywhere, and my local computer at home?

What do you run at home?

If your OS is not an ---x, you can try something like:

s = os.getcwd()
local = (s[:5] != "/home")

There are probably lots of variations on this, depending on what exactly you use at home.

Jim

You might also be able to use

from socket import gethostname
im_running_on = gethostname()

The hostnames for PythonAnywhere servers change between deploys and depending on which console server your code is running on, but I guess your dev server hostname should be constant.

Thanks for the responses, Jim and Glenn!

I'm going to use socket.gethostname() method, very simple and straightforward, and my hostname at home stays consistent.