user469652 user469652 - 20 days ago 5
Python Question

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

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

I generally put something like this in settings.py:

import socket

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