Django - How to simply get domain name?

Maître Van Diest picture Maître Van Diest · Apr 29, 2015 · Viewed 18.5k times · Source

Firstly, I want to say that I'm a beginner in Django.

I'm looking for a simple way to retrieve the domain name of my Django website.

I want to do this in my settings.py. I've already tried with the socket something like this:

socket.gethostname()

but this doesn't work correctly.

Answer

Imprfectluck picture Imprfectluck · Apr 29, 2015

If you have a request object,do

request.META['HTTP_HOST']

This would return the hostname