Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - How to simply get domain name? [duplicate]

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.

like image 218
Maître Van Diest Avatar asked Apr 29 '15 13:04

Maître Van Diest


1 Answers

If you have a request object,do

request.META['HTTP_HOST']

This would return the hostname

like image 107
Imprfectluck Avatar answered Oct 12 '22 00:10

Imprfectluck