问题
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?
回答1:
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:
- http://docs.wagtail.io/en/v1.13.1/reference/pages/model_reference.html#wagtail.wagtailcore.models.Page.get_url_parts
- http://docs.wagtail.io/en/v1.13.1/topics/pages.html#customising-url-patterns-for-a-page-model
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, '/')
来源:https://stackoverflow.com/questions/48468506/change-href-of-live-status-link-in-wagtail-admin