简体   繁体   中英

NoReverseMatch at /admin/pages/ on wagtail

I am getting the following error and cannot figure out where the error is

NoReverseMatch at /admin/pages/new/blog/blogpage/7/ Reverse for 'wagtail_serve' with arguments '(u'blog//',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['((?:[\\w\\-]+/)*)$']

This happens whenever I try to create a new blogpost in accordance to the wagtail demo. I am using django 1.8.3

Having looked at the solution here https://groups.google.com/forum/#!msg/wagtail/RTzQyf8ec34/oOaupmu7rkUJ I can confirm that the wagtail urls are on included on my urls.py file

Here is my models.py file

from django.db import models

from wagtail.wagtailsearch import index
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailadmin.edit_handlers import (FieldPanel,
                                                InlinePanel,
                                                MultiFieldPanel,
                                                PageChooserPanel)
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel

from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey

from taggit.models import Tag, TaggedItemBase

from django.shortcuts import render

class BlogPageTag(TaggedItemBase):
    content_object = ParentalKey('blog.BlogPage', related_name='tagged_items')

class BlogPage(Page):
    main_image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    date = models.DateField("Post date")
    intro = models.CharField(max_length=250)
    body = RichTextField(blank=True)
    tags = ClusterTaggableManager(through=BlogPageTag, blank=True)

    search_fields = Page.search_fields + (
        index.SearchField('intro'),
        index.SearchField('body'),
    )

    content_panels = Page.content_panels + [
        FieldPanel('date'),
        ImageChooserPanel('main_image'),
        FieldPanel('intro'),
        FieldPanel('body', classname="full")
    ]

BlogPage.promote_panels = [
    FieldPanel('tags'),
]

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

    @property
    def link(self):
        if self.link_page:
            return self.link_page.url
        else:
            return self.link_external

    panels = [
        FieldPanel('link_external'),
        PageChooserPanel('link_page'),
    ]

    class Meta:
        abstract = True


# Related links
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 BlogIndexRelatedLink(Orderable, RelatedLink):
    page = ParentalKey('BlogIndexPage', related_name='related_links')

class BlogIndexPage(Page):
    intro = RichTextField(blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('intro', classname="full"),
        InlinePanel('related_links', label="Related links"),
    ]


    @property
    def blogs(self):
        # Get list of live blog pages that are descendants of this page

        blogs = BlogPage.objects.live().descendant_of(self) 
        # Order by most recent date first
        blogs = blogs.order_by('-date')

        return blogs


    def serve(self, request):
        # Get blogs
        blogs = self.blogs

        # Filter by tag
        tag = request.GET.get('tag')
        if tag:
            blogs = blogs.filter(tags__name=tag)
            print blogs
            return render(request, self.template, {
                'self': self,
                'blogs': blogs,
            })

        else:
            # Display event page as usual
            return super(BlogIndexPage, self).serve(request)

class Gallery(Page):
    image1 = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    image2 = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    image3 = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    image4 = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    image5 = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    image6 = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )


    content_panels = Page.content_panels + [
       ImageChooserPanel('image1'),
       ImageChooserPanel('image2'),
       ImageChooserPanel('image3'),
       ImageChooserPanel('image4'),
       ImageChooserPanel('image5'),
       ImageChooserPanel('image6'),

    ]

Here is the fill stacktrace

Environment:


Request Method: POST
Request URL: http://localhost:8000/admin/pages/new/blog/blogpage/7/

Django Version: 1.8.3
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'taggit',
 'compressor',
 'modelcluster',
 'wagtail.wagtailcore',
 'wagtail.wagtailadmin',
 'wagtail.wagtailsearch',
 'wagtail.wagtailimages',
 'wagtail.wagtaildocs',
 'wagtail.wagtailsnippets',
 'wagtail.wagtailusers',
 'wagtail.wagtailsites',
 'wagtail.wagtailembeds',
 'wagtail.wagtailredirects',
 'wagtail.wagtailforms',
 'search',
 'home',
 'apps.blog',
 'apps.thingspeak',
 'jsonfield')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'wagtail.wagtailcore.middleware.SiteMiddleware',
 'wagtail.wagtailredirects.middleware.RedirectMiddleware')


Traceback:
File "/home/upande/.virtualenvs/mamase/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/upande/.virtualenvs/mamase/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _cache_controlled
  43.             response = viewfunc(request, *args, **kw)
File "/home/upande/.virtualenvs/mamase/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  22.                 return view_func(request, *args, **kwargs)
File "/home/upande/.virtualenvs/mamase/local/lib/python2.7/site-packages/wagtail/wagtailadmin/views/pages.py" in create
  177.                     messages.button(page.url, _('View live')),
File "/home/upande/.virtualenvs/mamase/local/lib/python2.7/site-packages/wagtail/wagtailcore/models.py" in url
  592.                 return ('' if len(root_paths) == 1 else root_url) + reverse('wagtail_serve', args=(self.url_path[len(root_path):],))
File "/home/upande/.virtualenvs/mamase/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
  579.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "/home/upande/.virtualenvs/mamase/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  496.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /admin/pages/new/blog/blogpage/7/
Exception Value: Reverse for 'wagtail_serve' with arguments '(u'blog//',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['((?:[\\w\\-]+/)*)$']

The problem is here:

BlogPage.promote_panels = [
    FieldPanel('tags'),
]

The promote_panels list here is missing the fields from the basic Page class, such as the page slug - as a result, you're creating a page without a slug, which has no valid URL. This definition should be:

BlogPage.promote_panels = Page.promote_panels + [
    FieldPanel('tags'),
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM