def get_requested_page(site, request, path):
"""Retrieve a page from a site given a request and path.
This method uses the standard `wagtail.wagtailcore.Page.route` method
to retrieve a page using its path from the given site root.
If a requested page exists and is published, the result of `Page.route`
can be returned directly.
If the page exists but is not yet published, `Page.route` raises an
`Http404`, which this method tries to catch and handle. `Page.route`
raises `Http404` in two cases: if no page with the given path exists
and if a page exists but is unpublished. This method catches both
cases, and, if they fall into the latter category, returns the
requested page back to the caller despite its draft status.
"""
path_components = [
component for component in path.split('/') if component
]
try:
return site.root_page.route(request, path_components)
except Http404:
exception_source = inspect.trace()[-1]
stack_frame = exception_source[0]
page = stack_frame.f_locals['self']
path_components = stack_frame.f_locals['path_components']
if path_components:
raise
return page, [], {}
评论列表
文章目录