Recursive function to extract all url details

def _get_view_details(self, urlpatterns, parent=''):
        """Recursive function to extract all url details"""
        for pattern in urlpatterns:
            if isinstance(pattern, (URLPattern, RegexURLPattern)):
                try:
                    d = describe_pattern(pattern)
                    docstr = pattern.callback.__doc__
                    method = None
                    expected_json_response = ''

                    expected_url = ''
                    if docstr:
                        # Get expected URL
                        u = re.findall(r'URL: (.*)', docstr, flags=re.DOTALL)
                        if u:
                            expected_url = u[0]

                    # Get all possible methods
                    if 'view_class' not in dir(pattern.callback):
                        continue

                    possible_methods = [m for m in dir(pattern.callback.view_class) if m in METHODS]

                    for method in possible_methods:
                        view_method_docstr = getattr(pattern.callback.view_class, method).__doc__
                        if view_method_docstr:
                            # Check if method is modifier
                            if method in ['put', 'patch', 'delete']:
                                self.url_details.append({
                                    'url': expected_url,
                                    'method': method
                                })
                                continue
                            # Extract request method and JSON response from docstring of request method
                            j = re.findall(r'```(.*)```', view_method_docstr, flags=re.DOTALL)
                            if j is not None:
                                for match in j:
                                    expected_json_response = match.strip()
                                    # Only add the details if all 3 values are filled
                                    if method is not None and expected_json_response and expected_url:
                                        self.url_details.append({
                                            'url': expected_url,
                                            'method': method,
                                            'response': expected_json_response
                                        })
                                        continue

                except ViewDoesNotExist:
                    pass

            elif isinstance(pattern, (URLResolver, RegexURLResolver)):
                try:
                    patterns = pattern.url_patterns
                except ImportError:
                    continue

                d = describe_pattern(pattern)
                current_full_url = parent + d
                self._get_view_details(patterns, current_full_url)