wagtail pages giving `none` url with `live` status
Asked Answered
F

1

9

I am having some troubles with wagtail pages.

from the shell

>>> Site.get_site_root_paths()
[(1, u'/home/', u'http://localhost')]
>>> BlogPage.objects.all()[0]
<BlogPage: Hello wagtail>
>>> BlogPage.objects.all()[0].url
>>> BlogPage.objects.all()[0].full_url
>>> BlogPage.objects.all()[0].status_string
'live'
>>> BlogPage.objects.all()[0].url_path
u'/blog/hello-wagtail/'

It worked for a while, I moved the Blog Page from the root to a Blog Index Page in the wagtail admin (see models.py bellow) and for some reason, the page I moved disapeared from the admin so I tried to repeat the steps I did by creating my database again with ./manage.py sycndb and ./manage.py migrate, created pages again and now urls are not showing up anymore.

I added a breakpoint in wagtailcore/models.py to see what's going on. Critical section seems to be around here:

@property
    def url(self):
        """
        Return the 'most appropriate' URL for referring to this page from the pages we serve,
        within the Wagtail backend and actual website templates;
        this is the local URL (starting with '/') if we're only running a single site
        (i.e. we know that whatever the current page is being served from, this link will be on the
        same domain), and the full URL (with domain) if not.
        Return None if the page is not routable.
        """
        root_paths = Site.get_site_root_paths()
        for (id, root_path, root_url) in Site.get_site_root_paths():
            if self.url_path.startswith(root_path):
                return ('' if len(root_paths) == 1 else root_url) + self.url_path[len(root_path) - 1:]

self.url_path.startswith(root_path) is never true in my case.

Variables inside that loop:

id = {int} 1
root_path = {unicode} u'/home/'
root_paths = {list} [(1, u'/home/', u'http://localhost')]
root_url = {unicode} u'http://localhost'
self = {Page} Blog

All of that means that my created pages are not routable. I can still view my pages correctly using the preview mode from wagtail admin, but I can't find why there's no route to my pages :(.

Here's my models.py

from django.db import models

from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel, InlinePanel, PageChooserPanel
from modelcluster.fields import ParentalKey


class BlogPage(Page):
    body = RichTextField()
    intro = RichTextField()
    date = models.DateField("Post date")
    indexed_fields = ('body', )
    search_name = "Blog Page"


BlogPage.content_panels = [
    FieldPanel('title', classname="full title"),
    FieldPanel('date'),
    FieldPanel('intro', classname="full"),
    FieldPanel('body', classname="full"),
]


class LinkFields(models.Model):
    link_page = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        blank=True,
        related_name='+'
    )

    panels = [
        PageChooserPanel('link_page'),
    ]

    class Meta:
        abstract = True


class RelatedLink(LinkFields):
    title = models.CharField(max_length=255, help_text="Link title")
    panels = [
        FieldPanel('title'),
        MultiFieldPanel(LinkFields.panels, "Link"),
    ]

    class Meta:
        abstract = True


class BlogIndexPageRelatedLink(Orderable, RelatedLink):
    page = ParentalKey('main.BlogIndexPage', related_name='related_links')


class BlogIndexPage(Page):
    intro = models.CharField(max_length=256)
    indexed_fields = ('body', )
    search_name = "Blog Index Page"


BlogIndexPage.content_panels = [
    FieldPanel('title', classname="full title"),
    FieldPanel('intro', classname="full"),
    InlinePanel(BlogIndexPage, 'related_links', label="Related links"),
]
Floatplane answered 26/7, 2014 at 23:50 Comment(0)
C
10

Generally you should create pages as children of the homepage. Internally, this means that your blog index page will receive a url_path of /home/blog/, and since /home/ is mapped to http://localhost in the root_paths list, this will give it a final URL of http://localhost/blog/.

As you've seen, if you create pages at the root level alongside the homepage, they will exist outside of the default Site record, and so they won't have a routable URL. However, you can set up additional sites through the Django admin interface at http://localhost/django-admin/ - for example, if you wanted to host your blog at http://blog.example.com/, you would create a Site entry for that domain rooted at your blog index page.

Collocutor answered 28/7, 2014 at 9:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.