code: def set_maintenance_mode(value):
      
  
      # If maintenance mode is defined in settings, it can't be changed.
      if settings.MAINTENANCE_MODE is not None:
          raise ImproperlyConfigured(
              'Maintenance mode cannot be set dynamically '
              'if defined in settings.')
  
      if not isinstance(value, bool):
          raise TypeError('value argument type is not boolean')
  
      backend = get_maintenance_mode_backend()
      backend.set_value(value)
docs: Set maintenance_mode state to state file.