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
:
- # <INSTALLED_ADDONS> # Warning: text inside the INSTALLED_ADDONS tags is auto-generated. Manual changes will be overwritten.
- # </INSTALLED_ADDONS>
- django-axes==2.3.2
- 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:
- if DEBUG:
- [...]
- def _show_toolbar(request):
- 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 DEBUG
mode:
- from django.conf import settings
- [...]
- if settings.DEBUG:
- import debug_toolbar
- urlpatterns = [
- ] + 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.