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):
            site_id, site_root_url, relative_page_path = self.get_url_parts()
            ret = relative_page_path
        except TypeError:
            ret = None
        return ret



Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo