Install specified middleware

def install_middleware(middleware_name, lookup_names=None):
    """
    Install specified middleware
    """
    if lookup_names is None:
        lookup_names = (middleware_name,)
    # default settings.MIDDLEWARE is None
    middleware_attr = 'MIDDLEWARE' if getattr(settings,
                                              'MIDDLEWARE',
                                              None) is not None \
        else 'MIDDLEWARE_CLASSES'
    # make sure to get an empty tuple when attr is None
    middleware = getattr(settings, middleware_attr, ()) or ()
    if set(lookup_names).isdisjoint(set(middleware)):
        setattr(settings,
                middleware_attr,
                type(middleware)((middleware_name,)) + middleware)