Wagtail get_absolute_url, without domain
Django models are usually created with a
get_absolute_url method, but Wagtail pages don't have one. On this site I mix Wagtail pages with other Django models and needed an url without a domain in some places, below is the solution I'm using right now. Most methods to get a page page seem to want a request object and add the domain, but I just wanted the full path to the page.
from wagtail.core.models import Page class MyPage(Page): def get_absolute_url(self): try: site_id, site_root_url, relative_page_path = self.get_url_parts() ret = relative_page_path except TypeError: ret = None return ret