本文整理汇总了Python中wagtail.contrib.routable_page.models.route方法的典型用法代码示例。如果您正苦于以下问题:Python models.route方法的具体用法?Python models.route怎么用?Python models.route使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.contrib.routable_page.models
的用法示例。
在下文中一共展示了models.route方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: route
# 需要导入模块: from wagtail.contrib.routable_page import models [as 别名]
# 或者: from wagtail.contrib.routable_page.models import route [as 别名]
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: _getExtraContext
# 需要导入模块: from wagtail.contrib.routable_page import models [as 别名]
# 或者: from wagtail.contrib.routable_page.models import route [as 别名]
def _getExtraContext(self, route):
return {}