URLs¶
Canonicalize a URL¶
Canonicalization turns a relative URL into a complete URL.
To canonicalize a URL, use this function:
- indieweb_utils.canonicalize_url(url: str, domain: str = '', full_url: str = '', protocol: str = 'https') str [source]¶
Return a canonical URL for the given URL.
- Parameters
- Returns
The canonical URL.
- Return type
import indieweb_utils url = "/contact" domain = "jamesg.blog" protocol = "https" endpoints = indieweb_utils.canonicalize_url( url, domain, protocol=protocol ) print(webmention_endpoint) # https://jamesg.blog/contact/
This function returns a URL with a protocol, host, and path.
The domain of the resource is needed so that it can be added to the URL during canonicalization if the URL is relative.
A complete URL returned by this function looks like this:
https://indieweb.org/POSSE