|
@@ -28,11 +28,12 @@ from .utils import get_callable
|
|
|
|
|
|
|
|
|
class ResolverMatch:
|
|
|
- def __init__(self, func, args, kwargs, url_name=None, app_names=None, namespaces=None):
|
|
|
+ def __init__(self, func, args, kwargs, url_name=None, app_names=None, namespaces=None, route=None):
|
|
|
self.func = func
|
|
|
self.args = args
|
|
|
self.kwargs = kwargs
|
|
|
self.url_name = url_name
|
|
|
+ self.route = route
|
|
|
|
|
|
# If a URLRegexResolver doesn't have a namespace or app_name, it passes
|
|
|
# in an empty value.
|
|
@@ -55,9 +56,9 @@ class ResolverMatch:
|
|
|
return (self.func, self.args, self.kwargs)[index]
|
|
|
|
|
|
def __repr__(self):
|
|
|
- return "ResolverMatch(func=%s, args=%s, kwargs=%s, url_name=%s, app_names=%s, namespaces=%s)" % (
|
|
|
+ return "ResolverMatch(func=%s, args=%s, kwargs=%s, url_name=%s, app_names=%s, namespaces=%s, route=%s)" % (
|
|
|
self._func_path, self.args, self.kwargs, self.url_name,
|
|
|
- self.app_names, self.namespaces,
|
|
|
+ self.app_names, self.namespaces, self.route,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -345,7 +346,7 @@ class URLPattern:
|
|
|
new_path, args, kwargs = match
|
|
|
# Pass any extra_kwargs as **kwargs.
|
|
|
kwargs.update(self.default_args)
|
|
|
- return ResolverMatch(self.callback, args, kwargs, self.pattern.name)
|
|
|
+ return ResolverMatch(self.callback, args, kwargs, self.pattern.name, route=str(self.pattern))
|
|
|
|
|
|
@cached_property
|
|
|
def lookup_str(self):
|
|
@@ -503,6 +504,15 @@ class URLResolver:
|
|
|
self._populate()
|
|
|
return self._app_dict[language_code]
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def _join_route(route1, route2):
|
|
|
+ """Join two routes, without the starting ^ in the second route."""
|
|
|
+ if not route1:
|
|
|
+ return route2
|
|
|
+ if route2.startswith('^'):
|
|
|
+ route2 = route2[1:]
|
|
|
+ return route1 + route2
|
|
|
+
|
|
|
def _is_callback(self, name):
|
|
|
if not self._populated:
|
|
|
self._populate()
|
|
@@ -534,6 +544,7 @@ class URLResolver:
|
|
|
sub_match_args = sub_match.args
|
|
|
if not sub_match_dict:
|
|
|
sub_match_args = args + sub_match.args
|
|
|
+ current_route = '' if isinstance(pattern, URLPattern) else str(pattern.pattern)
|
|
|
return ResolverMatch(
|
|
|
sub_match.func,
|
|
|
sub_match_args,
|
|
@@ -541,6 +552,7 @@ class URLResolver:
|
|
|
sub_match.url_name,
|
|
|
[self.app_name] + sub_match.app_names,
|
|
|
[self.namespace] + sub_match.namespaces,
|
|
|
+ self._join_route(current_route, sub_match.route),
|
|
|
)
|
|
|
tried.append([pattern])
|
|
|
raise Resolver404({'tried': tried, 'path': new_path})
|