How can I remove the Django Toolbar?

Problem

By default, Open edX displays the Django Toolbar on the right-hand side of all LMS and Studio pages. This can be useful, but it also appears to cause a performance hit, so many developers disable it.

Solution

Put the following code into the file private.py in the directories lms/envs and cms/envs

from .common import INSTALLED_APPS, MIDDLEWARE_CLASSES

def tuple_without(source_tuple, exclusion_list):
    """Return new tuple excluding any entries in the exclusion list. Needed because tuples
    are immutable. Order preserved."""
    return tuple([i for i in source_tuple if i not in exclusion_list])

INSTALLED_APPS = tuple_without(INSTALLED_APPS, ['debug_toolbar', 'debug_toolbar_mongo'])
MIDDLEWARE_CLASSES = tuple_without(MIDDLEWARE_CLASSES, [
    'django_comment_client.utils.QueryCountDebugMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
])

DEBUG_TOOLBAR_MONGO_STACKTRACES = False

OAUTH_ENFORCE_SECURE = ""

import contracts
contracts.disable_all()