views.py 文件源码

python
阅读 57 收藏 0 点赞 0 评论 0

项目:wagtail-sharing 作者: cfpb 项目源码 文件源码
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, [], {}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号