django中获得当前域名

    # request.is_secure()
    #如果是https则为True,反之为False
    http = urlsplit(request.build_absolute_uri(None)).scheme
    #获得当前的HTTP或HTTPS
    host = request.META['HTTP_HOST']
    #获取当前域名
    shorturl = http + '://' + host + '/' + shorturl1 + '/'
    # shorturl = re.search(r'http[s]?://[^/]+', url).group()+'/'+shorturl1+'/'

 

转载于:https://www.cnblogs.com/lihao-like/p/9717740.html

你可能感兴趣的:(django中获得当前域名)