UPDATE: See Peter’s comment below for a slightly revised (and better) version of this.
The Django Debug Toolbar is essential for developing Django applications but it comes short in one area – Ajax. There’s been progress over the last couple years but the latest pull request for a panel that supports Ajax has yet to be completed and merged. This leaves you pretty much in the dark when making XHR requests as the toolbar only works if the mimetype of the response is either
application/xhtml+xml and contains a closing
</body> tag (otherwise your XHR requests would be filled with a bunch of junk from the toolbar).
After digging around I stumbled upon this SO post which details a few solutions including using the following middleware:
Add this middleware right after the debug toolbar in your settings (and ensure that it is only enabled for your dev environment) and then load an Ajax URL directly in a browser tab. The middleware simply detects that you’re not making this request as Ajax and wraps the response in some HTML which will activate the debug toolbar. Very handy.
It’s definitely a bit of a hack and doesn’t make working with posts very easy, but it’s better than nothing.