def getBaseURL(req):
 name = req.META['HTTP_HOST']
 try:
  name = name[:name.index(':')]
 except:
  pass
 try:
  port = int(req.META['SERVER_PORT'])
 except:
  port = 80
 proto = req.META['SERVER_PROTOCOL']
 if ('HTTPS' in proto):
  proto = 'https'
 else:
  proto = 'http'
 if ((port in [80, 443]) or (not port)):
  port = ''
 else:
  port = (':%s' % (port,))
 url = ('%s://%s%s/' % (proto, name, port))
 return url

def getBaseURL ( req ) : name = req . META [ 'HTTP_HOST' ] try : name = name [ : name . index ( ':' ) ] except : pass try : port = int ( req . META [ 'SERVER_PORT' ] ) except : port = 80 proto = req . META [ 'SERVER_PROTOCOL' ] if ( 'HTTPS' in proto ) : proto = 'https' else : proto = 'http' if ( ( port in [ 80 , 443 ] ) or ( not port ) ) : port = '' else : port = ( ':%s' % ( port , ) ) url = ( '%s://%s%s/' % ( proto , name , port ) ) return url
given a django web request object .