gpt4 book ai didi

Wagtail: custom URLs for blog page categories?(Wagail:博客页面类别的定制URL?)

转载 作者:bug小助手 更新时间:2023-10-25 23:54:26 30 4
gpt4 key购买 nike



My blog pages have a type and a subtype.

我的博客页面有一个类型和子类型。


I want blog page URLs to look like mysite.com/pages/<blog_type>/<blog_subtype>/<blog_title>

我希望博客页面URL看起来像mysite.com/pages/ / /


By default, they are just mysite.com/pages/<blog_title>

默认情况下,它们只是mysite.com/ages/


I can't think of a way to do this (I'm new to Wagtail). Can anyone help?

我想不出一种方法来做这件事(我是新手)。有谁能帮忙吗?


Thanks in advance

提前谢谢你


更多回答
优秀答案推荐

Routable pages will do what you're looking for:
https://docs.wagtail.org/en/stable/reference/contrib/routablepage.html

可路由页面将实现您想要的功能:https://docs.wagtail.org/en/stable/reference/contrib/routablepage.html


It does complicate a few things though:

但它确实使一些事情复杂化了:


If you're worried about SEO, you should choose one path and add this as your canonical link in your <head> section otherwise search engines won't know which to index (and also throw an error in the case of Google).

如果你担心搜索引擎优化,你应该选择一个路径,并将其作为你的规范链接添加到你的部分,否则搜索引擎将不知道索引哪个(在谷歌的情况下也会抛出错误)。


The basic would be <link rel="canonical" href="{{ self.full_url} }"> but you'd need to change that to reflect your modified route.

基本设置为 ,但您需要更改它以反映修改后的路由。


You'd be better adding a property to those pages that generates the url for you.

您最好向那些为您生成URL的页面添加一个属性。


You'd also need to override the default method for sitemap generation to add your custom url for these pages.

您还需要覆盖站点地图生成的默认方法,才能为这些页面添加自定义URL。


If you're indexing, you'll need to return the custom url in your search view as well.

如果你在索引,你还需要在你的搜索视图中返回定制的url。


更多回答

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com