How to use django-debug-toolbar for AJAX calls?

I'm curious if there is a reasonable way to use the (awesome) django-debug toolbar with AJAX requests.

For example, I use jQuery $ .get with a set of parameters to get into the Django URL and load it into a string. If I have an error, it is not registered in the toolbar. I also cannot use it when copying the AJAX URL, because DDT is attached to the body tag of the response, and it makes no sense to include body tags with AJAX responses.

Any direction would be helpful! Thank!

+47
python django django-debug-toolbar
Feb 26 2018-11-11T00:
source share
4 answers

I had the same problem before! And as I make more and more AJAX applications, I released the Django application and the Chrome extension which together solved exactly this problem.

All information is contained in the github repository.

+32
Oct 17 '13 at 5:55 on
source share

I wrote a query history panel for the Django Debug toolbar , which can be added to the Django Debug toolbar to view non-current requests (including AJAX requests).


Install via pip:

pip install git+https://github.com/djsutho/django-debug-toolbar-request-history.git 


In settings.py add 'ddt_request_history.panels.request_history.RequestHistoryPanel' to DEBUG_TOOLBAR_PANELS for example:

 DEBUG_TOOLBAR_PANELS = [ 'ddt_request_history.panels.request_history.RequestHistoryPanel', # Here it is 'debug_toolbar.panels.versions.VersionsPanel', 'debug_toolbar.panels.timer.TimerPanel', 'debug_toolbar.panels.settings.SettingsPanel', 'debug_toolbar.panels.headers.HeadersPanel', 'debug_toolbar.panels.request.RequestPanel', 'debug_toolbar.panels.sql.SQLPanel', 'debug_toolbar.panels.templates.TemplatesPanel', 'debug_toolbar.panels.staticfiles.StaticFilesPanel', 'debug_toolbar.panels.cache.CachePanel', 'debug_toolbar.panels.signals.SignalsPanel', 'debug_toolbar.panels.logging.LoggingPanel', 'debug_toolbar.panels.redirects.RedirectsPanel', 'debug_toolbar.panels.profiling.ProfilingPanel', ] 


To record ajax requests, redefine SHOW_TOOLBAR_CALLBACK in DEBUG_TOOLBAR_CONFIG (also in settings.py ), for example:

 DEBUG_TOOLBAR_CONFIG = { 'SHOW_TOOLBAR_CALLBACK': 'ddt_request_history.panels.request_history.allow_ajax', } 
+10
Jul 29 '14 at 14:13
source share

Ddt connects to the answer, which means that there is no standard way to view its panels for an AJAX request. In addition, the AJAX response may be in JSON format, which makes it impossible to include ddt in it.

Personally, would I find a way to register ddt output in a text file, or maybe it supports a client-server architecture in which the client works inside the AJAX request handler and sends data to the server? I do not know what is possible, since there are dozens of ddt clones.

+4
Feb 26 '11 at 12:11
source share

I hit this issue recently. My quick n-dirty but working solution was just to add some HTML views to bend the same code.

So, for example, if I see in NewRelic that 90% of my website’s time is spent calling ajax in / search _for_book? title =, my code might look something like this:

 views.py: def search_for_book(request, title): data = _search_for_book(title) return json_response(data) def test_search_for_book(request, title): data = _search_for_book(title) return http_response(data) 

The bottleneck will be somewhere in the _search_for_book code; we call it ajax, it does not matter for diagnosing its inefficiency (in my case, at least YMMV)

+4
Aug 07 '13 at
source share



All Articles