我在mydomain.com/gallery/album/2017上有类别过滤器
class Gallery(RoutablePageMixin,Page):
short_description = models.CharField(max_length=300,blank=True)
content_panels = Page.content_panels + [
FieldPanel('short_description'),
InlinePanel('image_gallery', label="image gallery"),
]
def get_posts(self):
return AlbumImageGallery.objects.all()
@route(r'^albums/(?P<album>[-\w]+)/$')
def post_by_category(self, request, album, *args, **kwargs):
self.get_posts = self.get_posts().filter(album__slug=album)
return Page.serve(self, request, *args, **kwargs)
def get_context(self, request, *args, **kwargs):
context = super(Gallery, self).get_context(request, *args, **kwargs)
context['albums'] = Album.objects.all()
context['album_image'] = AlbumImageGallery.objects.all()
context['get_posts'] = self.get_posts
context['gallery'] = self
return context
在我的HTML中
<a href="{% routablepageurl gallery "post_by_category" each.slug %}"> {{each.album_name}}</a>
现在我想从我的其他页面获取mydomain.com/gallery/album/2017
class MymodelPage(Page):
...
get_context():
context['gallery_images'] = Image.objects.all()
context['gallery'] = Gallery.objects.get()
MymodelPage.html
错误
NoReverseMatch at /media-corner/
Reverse for 'post_by_category' with arguments '('',)' not found. 1 pattern(s) tried: [u'albums/(?P<album>[-\\w]+)/$']
我想在我的Modal RoutablePageMixin上获取gallery url / slug 我试图传递url页面给我错误
答案 0 :(得分:0)
检查each.slug
的值。从错误消息(
with arguments '('',)'
),似乎routablepageurl
标记收到一个空字符串作为each.slug
参数。 (这不符合您的网址格式,因为它要求album
slug至少包含一个字符。)