4. Configure an application¶

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

    Note

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

    For these steps, running your project with:

    is a good way of monitoring progress.

    The latest stable version at the time of writing is 1.8, so adddjango-debug-toolbar==1.8 to requirements.in:

    1. # <INSTALLED_ADDONS> # Warning: text inside the INSTALLED_ADDONS tags is auto-generated. Manual changes will be overwritten.
    2. # </INSTALLED_ADDONS>
    3. django-axes==2.3.2
    4. django-debug-toolbar==1.8

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

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

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

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

    1. if DEBUG:
    2.  
    3. [...]
    4.  
    5. def _show_toolbar(request):
    6. DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": _show_toolbar}

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

    Our approach in the urls.py is similar: we only want it active in DEBUGmode:

    1. from django.conf import settings
    2.  
    3. [...]
    4.  
    5. if settings.DEBUG:
    6. import debug_toolbar
    7. urlpatterns = [
    8. ] + urlpatterns

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

    Visit the admin to see the Debug Toolbar in action.