Search code examples
pythondjangourlhost

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?


Solution

  • I generally put something like this in settings.py:

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