code: def get_directory(request):
      
  
      def get_url(url):
          return reverse(url, request=request) if url else url
  
      def is_active_url(path, url):
          return path.startswith(url) if url and path else False
  
      path = request.path
      directory_list = []
  
      def sort_key(r):
          return r[0]
  
      # TODO(ant): support arbitrarily nested
      # structure, for now it is capped at a single level
      # for UX reasons
      for group_name, endpoints in sorted(
          six.iteritems(directory),
          key=sort_key
      ):
          endpoints_list = []
          for endpoint_name, endpoint in sorted(
              six.iteritems(endpoints),
              key=sort_key
          ):
              if endpoint_name[:1] == '_':
                  continue
              endpoint_url = get_url(endpoint.get('_url', None))
              active = is_active_url(path, endpoint_url)
              endpoints_list.append(
                  (endpoint_name, endpoint_url, [], active)
              )
  
          url = get_url(endpoints.get('_url', None))
          active = is_active_url(path, url)
          directory_list.append(
              (group_name, url, endpoints_list, active)
          )
      return directory_list
docs: Get API directory as a nested list of lists.