MCPcopy
hub / github.com/django/django / resolve

Method resolve

django/urls/resolvers.py:670–717  ·  view source on GitHub ↗
(self, path)

Source from the content-addressed store, hash-verified

668 return name in self._callback_strs
669
670 def resolve(self, path):
671 path = str(path) # path may be a reverse_lazy object
672 tried = []
673 match = self.pattern.match(path)
674 if match:
675 new_path, args, kwargs = match
676 for pattern in self.url_patterns:
677 try:
678 sub_match = pattern.resolve(new_path)
679 except Resolver404 as e:
680 self._extend_tried(tried, pattern, e.args[0].get("tried"))
681 else:
682 if sub_match:
683 # Merge captured arguments in match with submatch
684 sub_match_dict = {**kwargs, **self.default_kwargs}
685 # Update the sub_match_dict with the kwargs from the
686 # sub_match.
687 sub_match_dict.update(sub_match.kwargs)
688 # If there are *any* named groups, ignore all non-named
689 # groups. Otherwise, pass all non-named arguments as
690 # positional arguments.
691 sub_match_args = sub_match.args
692 if not sub_match_dict:
693 sub_match_args = args + sub_match.args
694 current_route = (
695 ""
696 if isinstance(pattern, URLPattern)
697 else str(pattern.pattern)
698 )
699 self._extend_tried(tried, pattern, sub_match.tried)
700 return ResolverMatch(
701 sub_match.func,
702 sub_match_args,
703 sub_match_dict,
704 sub_match.url_name,
705 [self.app_name, *sub_match.app_names],
706 [self.namespace, *sub_match.namespaces],
707 self._join_route(current_route, sub_match.route),
708 tried,
709 captured_kwargs=sub_match.captured_kwargs,
710 extra_kwargs={
711 **self.default_kwargs,
712 **sub_match.extra_kwargs,
713 },
714 )
715 tried.append([pattern])
716 raise Resolver404({"tried": tried, "path": new_path})
717 raise Resolver404({"path": path})
718
719 @cached_property
720 def urlconf_module(self):

Callers

nothing calls this directly

Calls 9

_extend_triedMethod · 0.95
_join_routeMethod · 0.95
ResolverMatchClass · 0.85
Resolver404Class · 0.85
matchMethod · 0.45
resolveMethod · 0.45
getMethod · 0.45
updateMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected