How to use Django to get the name for the host server?

user469652 picture user469652 · Nov 4, 2010 · Viewed 51.8k times · Source

How to use Django to get the name for the host server?

I need the name of the hosting server instead of the client name?

Answer

Craig Trader picture Craig Trader · Nov 5, 2010

I generally put something like this in settings.py:

import socket

try:
    HOSTNAME = socket.gethostname()
except:
    HOSTNAME = 'localhost'