I'm having a surprisingly difficult time figuring out a good way to identify 
the hostname of the server that is running a background process. If it was a 
front-end thing, I could just use "request.env.http_host" or something. 
However, since it's a background process, there is no request (or really 
anything).

One approach is something like "import socket; host = socket.gethostname" 
which I think grabs it from /etc/hostname. However, I've seen it advised to 
only put the machine name in /etc/hostname, not the fully qualified domain 
name. Also, this doesn't seem to work on my Mac where I would expect 
127.0.0.1:8000 or localhost.

What I am trying to do is include the correct URL in emails when run on 
different staging servers (ie prod, qa, dev). And many of my emails or 
generated via background processes, not necessarily as a result of user 
action on a web page. Has anyone been doing this?

Reply via email to