【发布时间】:2020-01-16 13:13:20
【问题描述】:
我有一个 wagtail 项目,在根 (slug='home') 有一个“主页”页面。
第二个页面“博客”是“主页”的子页面 (slug='blog')。
最后,我的博客发布页面是“博客”的子级(slug='blog-post-1' 等)。
在blog/models.py我有以下代码:
class BlogListingPage(Page):
"""List the Blog detail pages."""
template = "blog/blog_listing_page.html"
....
def get_context(self, request, *args, **kwargs):
"""Add custom content to our context."""
context = super().get_context(request, *args, **kwargs)
context['blog_pages'] = self.get_children().live()
return context
class BlogDetailPage(Page):
"""Blog detail page."""
template = "blog/blog_detail_page.html"
....
访问我使用的博客:
<a class="nav-link" href="/blog">Blog</a>
而且效果很好。
现在,详细信息页面的 URL 是 /home/blog/blog-post-1/ 等,但页面实际上位于 /blog/blog-post-1/。
“/home”是从哪里来的,我该如何摆脱它?
【问题讨论】:
-
如何输出页面 URL? (你在使用
page.url_path吗?) -
@gasman 是的!你是怎么猜到的?
标签: wagtail