[Fixed]-Django – How to simply get domain name?

16👍

If you have a request object,do

request.META['HTTP_HOST']

This would return the hostname

9👍

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

from django.contrib.sites.models import Site

your_domain = Site.objects.get_current().domain

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

0👍

import platform
platform.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.”

Leave a comment