wagtail 4.0/如何从@path返回url(模板)以便在管理板中预览


class ProductIndexPage(RoutablePageMixin, Page):
subpage_types = ['ProductPage']
parent_page_types = ['home.HomePage']
def live_categories(self):
all_products_live_id = ProductPage.objects.live().values_list('categories_id', flat=True)
list_live_id_uniqe = list(set(all_products_live_id))
live_cat = ProductCategory.objects.filter(id__in=list_live_id_uniqe).order_by('-id')
return live_cat
@path('')
@path('all-categories/')
def all_category_page(self, request):
productpages = self.get_children().live().order_by('-first_published_at')
return self.render(request, context_overrides={
'title': self.title,
'productpages': productpages,
'live_categories': self.live_categories,
})
@path('<str:cat_name>/', name='cat_url')
def current_category_page(self, request, cat_name=None):
productpages = ProductPage.objects.live().filter(categories__slug__iexact=cat_name).order_by 
('-first_published_at')
current_cat = self.live_categories().get(slug=cat_name).name
return self.render(request, context_overrides={
'title': "%s" % current_cat,
'productpages': productpages,
'live_categories': self.live_categories,
})
@path('<str:cat_name>/<str:prod_name>/')
def product_page(self, request, cat_name=None, prod_name=None):
product = ProductPage.objects.get(categories__slug__iexact=cat_name, slug=prod_name)
return self.render(request, context_overrides={
'product': product},
template="products/product_page.html",)

我无法在wagtail管理菜单中编辑页面:

@path('<str:cat_name>/<str:prod_name>/')

我的页面树在admin:根/产品/& lt; prod_name>如何在管理员中更改路由,以便从移动按钮编辑页面或在管理员中预览?我是新手,请给我举个例子。英语不好意思)

使用RoutablePageMixin只有一个页面-它根据url上发送的参数显示不同。不幸的是,这意味着您不能预览页面的类别版本current_category_page。

但它看起来像你路由的产品页面@path('str:cat_name/str:prod_name/')应该显示与你从ProductPage自己的url服务相同的页面。所以预览中看到的ProductPage是ProductIndexPage + 'str:cat_name/str:prod_name/'

最新更新