code: def site_url(url):
      
      base_url = 'http://%s' % socket.gethostname()
  
      if server.port is not 80:
          base_url += ':%d' % server.port
  
      return urlparse.urljoin(base_url, url)
docs: Determine the server URL.