Django: Getting Started Transcripts
Chapter: 3rd Party Libraries for Django
Lecture: Django Debug Toolbar

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The next app is the Django debug toolbar. As the name implies, it is a toolbar that overlays your Django views, giving you access to all sorts of info,
0:10 for example, settings, headers, request information, the SQL queries that were run, static files, what templates were used and how they were inherited,
0:21 how the cache is behaving, and any signals that got fired or tracked. And in the spirit of Django it's applicable interface.
0:29 So there are even third party libraries built on top of this third party library to give you even more info.
0:35 Let's go see the debug toolbar in practice. You can probably guess the next few steps.
0:57 With the app installed, there's a couple more pieces of configuration. you need to be worried about.
1:02 The setup I've been using up till now already has them done but the tool bar won't work without them, so you need to make sure they're there.
1:10 First you have to be using Djangos static files app so it needs to be installed in installed apps. But like I said, you're probably doing that anyways.
1:22 Second, the template's actors value needs to be set to true. This tells Django that an app can have templates inside of it.
1:31 And as the toolbar uses this, you need to have this on. And finally, because it uses static files, you have to have a static URL defined.
1:45 All these values are the defaults but if you've been messing around, you need to make sure these are set correctly in order for the toolbar to work.
1:54 There's one more piece of configuration you need to do. Middleware is a pass through mechanism that all requests go through.
2:08 This allows you to write plugable code that impacts all the views in a project.
2:11 The debug toolbar does its magic by examining your views through this mechanism. Note that the order of placement here is important.
2:26 This should go as early as possible in the list but has to go after any encoding middleware so if you're compressing your views with zip,
2:34 this has to come after that. In my case, I don't have any of that going on so I just put it at the top.
2:42 For safety reason, the toolbar will only work against specific IP addresses.
2:46 This helps prevent you from accidentally enabling the toolbar in production.
2:50 I need to add a little more configuration to tell the toolbar where it can be used.
2:54 Setting internal IPs tells the toolbar it will only work for the local machine
3:11 which is about as locked down as you can be. As the toolbar has its own views. I need to add those views to my URL registry.
3:18 Let me open up alexandria URLs.py and there you go it's demo time.


Talk Python's Mastodon Michael Kennedy's Mastodon