@app.template_filter('external_url')
def external_url(url):
 url_pattern = '^(https?)://.*$'
 scheme = re.match(url_pattern, url)
 if (not scheme):
  url_root = request.url_root.rstrip('/')
  return '{}{}'.format(url_root, url)
 else:
  return url

@ app . template_filter ( 'external_url' ) def external_url ( url ) : url_pattern = '^(https?)://.*$' scheme = re . match ( url_pattern , url ) if ( not scheme ) : url_root = request . url_root . rstrip ( '/' ) return '{}{}' . format ( url_root , url ) else : return url
returns an external url for the given url .