Python源码示例:wagtail.contrib.routable.route()

示例1
def route(self, request, path_components):
        """
        Overrides RoutablePageMixin.route() to allow articles to have
        publish date components in URLs."""

        if len(path_components) >= 4:

            # Attempt to route to an article using date/slug components
            # NOTE: The page must have been published in order for
            # `first_published_at` to be set
            try:
                year = path_components[0]  # year
                month = path_components[1]  # month
                day = path_components[2]  # day
                slug = path_components[3]  # slug
                publish_date = date(int(year), int(month), int(day))
            except ValueError:
                # Date components invalid
                raise Http404

            try:
                # Find an article matching the above date and slug
                article = ArticlePage.objects.child_of(self).get(
                    publish_date=publish_date, slug=slug)
            except ArticlePage.DoesNotExist:
                raise Http404

            # Delegate further routing to the arcicle, excluding the
            # date and slug components used above
            return article.route(request, path_components[4:])

        return super().route(request, path_components) 
示例2
def _getExtraContext(self, route):
        return {}