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

一个人想着一个人 提交于 2019-12-05 01:28:56

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 Site

your_domain = Site.objects.get_current().domain

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

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."

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!