本文整理汇总了Python中django.urls.URLResolver方法的典型用法代码示例。如果您正苦于以下问题:Python urls.URLResolver方法的具体用法?Python urls.URLResolver怎么用?Python urls.URLResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.urls
的用法示例。
在下文中一共展示了urls.URLResolver方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_reversed_urlpatterns
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import URLResolver [as 别名]
def _get_reversed_urlpatterns(urlpatterns=urlpatterns):
"""Yields a list of all URLs that we can reverse with default args."""
for urlpattern in urlpatterns:
if isinstance(urlpattern, URLPattern):
try:
path = reverse(urlpattern.name, *urlpattern.default_args)
except NoReverseMatch:
pass
else:
yield path
elif isinstance(urlpattern, URLResolver):
# handle recursive urlpattern definitions
yield from _get_reversed_urlpatterns(urlpatterns=urlpattern.url_patterns)
示例2: get_resolver
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import URLResolver [as 别名]
def get_resolver(cls):
if '_routablepage_urlresolver' not in cls.__dict__:
subpage_urls = cls.get_subpage_urls()
cls._routablepage_urlresolver = URLResolver(RegexPattern(r'^/'), subpage_urls)
return cls._routablepage_urlresolver
示例3: list_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import URLResolver [as 别名]
def list_urls(lis, acc=None):
# ripped from stackoverflow
if acc is None:
acc = []
if not lis:
return
data = lis[0]
if isinstance(data, URLPattern):
yield acc + [str(data.pattern)]
elif isinstance(data, URLResolver):
yield from list_urls(data.url_patterns, acc + [str(data.pattern)])
yield from list_urls(lis[1:], acc)
示例4: tenant_patterns
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import URLResolver [as 别名]
def tenant_patterns(*urls):
"""
Add the tenant prefix to every URL pattern within this function.
This may only be used in the root URLconf, not in an included URLconf.
"""
return [URLResolver(TenantPrefixPattern(), list(urls))]
示例5: get_resolver
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import URLResolver [as 别名]
def get_resolver(url, url_config):
return URLResolver(RegexPattern(r'^{}'.format(url)), url_config)
示例6: route
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import URLResolver [as 别名]
def route(self, request, path_components):
if not self.live:
raise Http404
resolver = URLResolver(RegexPattern(r"^"), self.APP_PREFIX + self.app)
path = request.path[len(self.url):]
view, args, kwargs = resolver.resolve(path)
self._view = view
return (self, args, kwargs)