Configure an application

In the previous section of the tutorial, we added a couple of applications. However, they were extremely simple and required very minimal configuration in the project’s and In practice, adding a Django application to a project will require more complex configuration.

We’ll explore this by adding Django Debug Toolbar to the project.


At this stage we will assume that you have your project running locally. See Control your project and see its console for a refresher on how to control your project.

For these steps, running your project with:

docker-compose run --rm --service-ports web python runserver

is a good way of monitoring progress.

Add django-debug-toolbar to

The Django Debug Toolbar installation notes suggest to install it using pip install django-debug-toolbar.

The latest stable version at the time of writing is 1.8, so add django-debug-toolbar==1.8 to

# <INSTALLED_ADDONS>  # Warning: text inside the INSTALLED_ADDONS tags is auto-generated. Manual changes will be overwritten.

Run docker-compose build web to rebuild the project with the new requirement.


We want Django Debug Toolbar to be active only when running with DEBUG = True, so all configuration for it will be conditional on an if DEBUG test.


Debug Toolbar requires django.contrib.staticfiles and debug_toolbar to be present in INSTALLED_APPS. django.contrib.staticfiles is installed in Divio Cloud projects by default, so we just add debug_toolbar:



Configure Debug Toolbar settings

Normally, you’d set INTERNAL_IPS to ensure that this only runs on certain servers. With Docker, we don’t always know what internal IP address a project will have, so we can’t rely on that. However, relying on DEBUG will be enough, so we define a function that will serve as a SHOW_TOOLBAR_CALLBACK callback to replace the default:



    def _show_toolbar(request):
        return True


Configure middleware settings

The installation documents note that we must set up the middleware, and that it should come as soon as possible in the list “after any other middleware that encodes the response’s content, such as GZipMiddleware.”

So let’s insert it right after django.middleware.gzip.GZipMiddleware:



        MIDDLEWARE_CLASSES.index("django.middleware.gzip.GZipMiddleware") + 1,


Our approach in the is similar: we only want it active in DEBUG mode:

from django.conf import settings


if settings.DEBUG:
    import debug_toolbar
    urlpatterns = [
        url(r'^__debug__/', include(debug_toolbar.urls)),
    ] + urlpatterns

See the results

And that’s it (Debug Toolbar has no database tables, so you don’t need to run migrations).

Visit the admin to see the Debug Toolbar in action.

'Django Debug Toolbar'