django-debug-toolbar
django-debug-toolbar copied to clipboard
Alternative lightweight HTML injection
Hello! I mostly develop APIs in Python, trying things out with a command-line HTTP client. When things go bad, it is quite unfriendly to get a huge dump of HTML in the terminal and have to scroll up to find the error message.
In contrast, pyramid-debug-toolbar only injects a few lines in responses, with a link that you can open in your browser to see debug info, which works when testing in a browser or from any other HTTP client:
When you include the toolbar in your application, a floating Pyramid logo will appear on the upper right over your application's HTML. If you click on the Pyramid logo, a new target window will open with your current request highlighted and all of your configured panels loaded. — https://docs.pylonsproject.org/projects/pyramid_debugtoolbar/en/latest/#the-toolbar
This is the code injected, which lets the whole page for a 404 or 500 error fit in my terminal:
<link rel="stylesheet" type="text/css" href="http://localhost:1440/_debug_toolbar/static/toolbar/toolbar_button.css">
<div id="pDebug">
<div id="pDebugToolbarHandle">
<a title="Show Toolbar" id="pShowToolBarButton"
href="http://localhost:1440/_debug_toolbar/313430303532373735303634393132" target="pDebugToolbar">« FIXME: Debug Toolbar</a>
</div>
</div>
In the abstract, is this a feature that djdt developers would accept?
For the implementation. A new middleware would be needed to inject just the link, with a new view that does the same job as the current middleware (query panels to get the toolbar info, send requests to display more info for a panel). It doesn’t seem to require many changes, and the standard mode would be unchanged.
Sounds good. I can't promise much, but I'll certainly review/provide feedback.
I'm not sure I understand whether you're proposing to add another middleware besides the current one, or if you'd want to modify the existing middleware. I suspect that the later would be less work down the road because there's only one code path to maintain.
I suggested a new middleware to make sure that the current behaviour is left untouched, but if it makes sense to have conditions inside one same middleware, that could be done.
FTR, I am testing https://github.com/recamshak/django-debug-panel which works with JSON responses and lets me see history.
django-debug-panel is only compatible with chrome/chromium.
Related tickets: #981 #985