本文整理匯總了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, '', '', '']
)