中更改实时状态链接的

中更改实时状态链接的

本文介绍了在 Wagtail Admin 中更改实时状态链接的 href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 wagtail 制作了一个单页滚动网站.我有一个主页模型,其他所有内容都是子页面,例如关于我们、事件等.在管理页面上,它创建了一个带有子页面标题的 slug,这是实时状态链接使用的.例如,它是 .有没有办法完全更改实时状态链接?

I made a one page scrolling site using wagtail. I have a homepage model and everything else is child pages such as about us, events, etc. On the admin page it creates a slug with the title of the child page which is what the live status link uses. For example it is <a href="/about-us/">. Is there a way to change the live status link at all?

推荐答案

页面 URL 是通过调用页面模型上的 get_url_parts 方法构造的——通过覆盖这个方法,你可以自定义生成的 URL:

The page URL is constructed by calling the get_url_parts method on the page model - by overriding this method, you can customise the resulting URL:

通常,如果您要覆盖 get_url_parts,您需要对站点的 URL 路由行为进行相应的自定义,以确保该页面在相关 URL 处实际可用;这可以通过 RoutablePageMixin 来完成.但是,在这种情况下,听起来您只是将这些子页面用作页面内容的占位符,而不必担心它们可以通过自己的 URL 访问 - 因此您只需将/"作为页面返回即可路径:

Normally, if you're overriding get_url_parts, you'd want to make a corresponding customisation to your site's URL routing behaviour, to ensure that the page is actually available at the URL in question; this can be done with RoutablePageMixin. In this case, though, it sounds like you're just using these subpages as placeholders for page content, and aren't bothered about them being accessible at their own URL - so you can get away with simply returning '/' as the page path:

class MyChildPage(Page):
    # ...
    def get_url_parts(self, *args, **kwargs):
        url_parts = super(MyChildPage, self).get_url_parts(*args, **kwargs)

        if url_parts is None:
            # in this case, the page doesn't have a well-defined URL in the first place -
            # for example, it's been created at the top level of the page tree
            # and hasn't been associated with a site record
            return None

        site_id, root_url, page_path = url_parts

        # return '/' in place of the real page path
        return (site_id, root_url, '/')

这篇关于在 Wagtail Admin 中更改实时状态链接的 href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 18:49