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?
I generally put something like this in
import socket try: HOSTNAME = socket.gethostname() except: HOSTNAME = 'localhost'
If you have a request (e.g., this is inside a view), you can look at
request.get_host() which gets you a complete locname (host and port), taking into account reverse proxy headers if any. If you don't have a request, you should configure the hostname somewhere in your settings. Just looking at the system hostname can be ambiguous in a lot of cases, virtual hosts being the most common.