本文整理汇总了Python中django.core.urlresolvers.get_resolver方法的典型用法代码示例。如果您正苦于以下问题:Python urlresolvers.get_resolver方法的具体用法?Python urlresolvers.get_resolver怎么用?Python urlresolvers.get_resolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.urlresolvers
的用法示例。
在下文中一共展示了urlresolvers.get_resolver方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context_data
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_resolver [as 别名]
def get_context_data(self, **kwargs):
view = self.kwargs['view']
urlconf = urlresolvers.get_urlconf()
if urlresolvers.get_resolver(urlconf)._is_callback(view):
mod, func = urlresolvers.get_mod_func(view)
view_func = getattr(import_module(mod), func)
else:
raise Http404
title, body, metadata = utils.parse_docstring(view_func.__doc__)
if title:
title = utils.parse_rst(title, 'view', _('view:') + view)
if body:
body = utils.parse_rst(body, 'view', _('view:') + view)
for key in metadata:
metadata[key] = utils.parse_rst(metadata[key], 'model', _('view:') + view)
kwargs.update({
'name': view,
'summary': title,
'body': body,
'meta': metadata,
})
return super(ViewDetailView, self).get_context_data(**kwargs)
示例2: resolve
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_resolver [as 别名]
def resolve(
self,
path, # type: str
urlconf=None, # type: Union[None, Tuple[URLPattern, URLPattern, URLResolver], Tuple[URLPattern]]
):
# type: (...) -> str
resolver = get_resolver(urlconf)
match = self._resolve(resolver, path)
return match or path
示例3: outer_get_resolver
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_resolver [as 别名]
def outer_get_resolver(urlconf):
return inner_get_resolver(urlconf, system_layout.current_value)
# Monkey patching `django.core.urlresolvers.get_resolver` doesn't completely
# solve the problem in Django 1.8.3 because
# `django.core.handlers.base.BaseHandler` creates a new
# `django.core.urlresolvers.RegexURLResolver` on every request. This is
# addressed by ticket #14200 (https://code.djangoproject.com/ticket/14200).
# A patch for this problem has been written and accepted, and should appear in
# the next Django release. Until then, we essentially apply the accepted patch
# ourselves by monkey patching `BaseHandler.get_response`.
示例4: patch_resolvers
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_resolver [as 别名]
def patch_resolvers():
urlresolvers.get_resolver = outer_get_resolver
BaseHandler.get_response = new_get_response
if PATCH_SWAGGER and not hasattr(UrlParser, 'old_get_apis'):
UrlParser.old_get_apis = UrlParser.get_apis
UrlParser.get_apis = new_get_apis
示例5: url_to_template
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_resolver [as 别名]
def url_to_template(self, view_name, request, template_name):
resolver = urlresolvers.get_resolver(None)
info = resolver.reverse_dict[view_name]
path_template = info[0][0][0]
# FIXME: what happens when URL has more than one dynamic values?
# e.g. nested relations: manufacturer/%(id)s/cars/%(card_id)s
path = path_template % {info[0][0][1][0]: '{%s}' % template_name}
parsed_url = urlparse(request.build_absolute_uri())
return urlunparse(
[parsed_url.scheme, parsed_url.netloc, path, '', '', '']
)