code: def _check_middleware_dependencies(concerned_object, required_middleware):
      
      declared_middleware = getattr(settings, 'MIDDLEWARE', None)
      if declared_middleware is None:
          declared_middleware = settings.MIDDLEWARE_CLASSES  # Django 1.8 support
  
      # Filter out all the middleware except the ones we care about for ordering.
      matching_middleware = [mw for mw in declared_middleware if mw in required_middleware]
      if required_middleware != matching_middleware:
          raise AssertionError(
              "{} requires middleware order {} but matching middleware was {}".format(
                  concerned_object, required_middleware, matching_middleware
              )
          )
docs: Check required middleware dependencies exist and in the correct order.
  
      Args:
          concerned_object (object): The object for which the required
              middleware is being checked. This is used for error messages only.
          required_middleware (list of String): An ordered list representing the
              required middleware to be checked.
  
      Usage:
          Add in __init__ method to a Middleware class to have its dependencies
          checked on startup.
  
          def __init__(self):
              super(SomeMiddleware, self).__init__()
              _check_middleware_dependencies(self, required_middleware=[
                  'edx_django_utils.cache.middleware.RequestCacheMiddleware',
              ])
  
      Raises:
          AssertionError if the provided dependencies don't appear in
              MIDDLEWARE_CLASSES in the correct order.