本文整理汇总了Python中django.urls.resolvers.RegexPattern方法的典型用法代码示例。如果您正苦于以下问题:Python resolvers.RegexPattern方法的具体用法?Python resolvers.RegexPattern怎么用?Python resolvers.RegexPattern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.urls.resolvers
的用法示例。
在下文中一共展示了resolvers.RegexPattern方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: url_object
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [as 别名]
def url_object(self) -> RegexPattern:
return url(self.url, self.function)
示例2: get_resolver
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [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: get_resolver
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [as 别名]
def get_resolver(url, url_config):
return URLResolver(RegexPattern(r'^{}'.format(url)), url_config)
示例4: get_regex_pattern
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [as 别名]
def get_regex_pattern(urlpattern):
"""
Get the raw regex out of the urlpattern's RegexPattern or RoutePattern. This is always a regular expression,
unlike get_original_route above.
"""
if hasattr(urlpattern, 'pattern'):
# Django 2.0
return urlpattern.pattern.regex.pattern
else:
# Django < 2.0
return urlpattern.regex.pattern
示例5: make_url_resolver
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [as 别名]
def make_url_resolver(regex, urlpatterns):
try:
# Django 2.0
from django.urls.resolvers import RegexPattern
return URLResolver(RegexPattern(regex), urlpatterns)
except ImportError:
# Django < 2.0
return URLResolver(regex, urlpatterns)
示例6: route
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [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)
示例7: test_str
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [as 别名]
def test_str(self):
self.assertEqual(str(RegexPattern(_('^translated/$'))), '^translated/$')
示例8: test_no_urls_exception
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [as 别名]
def test_no_urls_exception(self):
"""
URLResolver should raise an exception when no urlpatterns exist.
"""
resolver = URLResolver(RegexPattern(r'^$'), settings.ROOT_URLCONF)
with self.assertRaisesMessage(
ImproperlyConfigured,
"The included URLconf 'urlpatterns_reverse.no_urls' does not "
"appear to have any patterns in it. If you see valid patterns in "
"the file then the issue is probably caused by a circular import."
):
getattr(resolver, 'url_patterns')
示例9: test_populate_concurrency
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [as 别名]
def test_populate_concurrency(self):
"""
URLResolver._populate() can be called concurrently, but not more
than once per thread (#26888).
"""
resolver = URLResolver(RegexPattern(r'^/'), 'urlpatterns_reverse.urls')
resolver._local.populating = True
thread = threading.Thread(target=resolver._populate)
thread.start()
thread.join()
self.assertNotEqual(resolver._reverse_dict, {})
示例10: setUp
# 需要导入模块: from django.urls import resolvers [as 别名]
# 或者: from django.urls.resolvers import RegexPattern [as 别名]
def setUp(self):
urlconf = 'urlpatterns_reverse.urls_error_handlers'
urlconf_callables = 'urlpatterns_reverse.urls_error_handlers_callables'
self.resolver = URLResolver(RegexPattern(r'^$'), urlconf)
self.callable_resolver = URLResolver(RegexPattern(r'^$'), urlconf_callables)