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

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


If you have a request object,do

request.META['HTTP_HOST']

This would return the hostname


If you're using django.contrib.sites framework:

from django.contrib.sites.models import Siteyour_domain = Site.objects.get_current().domain

Reference: https://docs.djangoproject.com/en/1.8/ref/contrib/sites/


import platformplatform.node()

from the docs:

"Returns the computer’s network name (may not be fully qualified!). An empty string is returned if the value cannot be determined."