NoReverseMatch at / admin / pages / on wagtail

时间:2015-07-24 10:49:25

标签: python django wagtail

我收到以下错误,无法确定错误的位置

  

NoReverseMatch at / admin / pages / new / blog / blogpage / 7 / Reverse for   ' wagtail_serve'有论据'(你'博客//',)'和关键字参数   ' {}'未找到。尝试了1种模式:['((?:[\ w \ - ] + /)*)$']

每当我尝试根据wagtail演示创建新的博客帖子时,就会发生这种情况。我正在使用django 1.8.3

在这里查看解决方案https://groups.google.com/forum/#!msg/wagtail/RTzQyf8ec34/oOaupmu7rkUJ我可以确认我的urls.py文件中包含了wagtail网址

这是我的models.py文件

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'),

    ]

这是填充堆栈跟踪

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\\-]+/)*)$']

1 个答案:

答案 0 :(得分:1)

问题在于:

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

此处的promote_panels列表缺少基本Page类中的字段,例如页面slug - 因此,您创建的页面没有slug,该页面没有有效的URL。这个定义应该是:

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