Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

python - How to use django-debug-toolbar on AJAX calls?

I'm curious if there's a reasonable way to use the (amazing) django-debug-toolbar with AJAX queries.

For example, I use a jQuery $.get with a bunch of parameters to hit a Django URL and load it inline. If I have an error with that, it isn't registered on the toolbar. I also can't use it by copying the AJAX URL because DDT attaches to the body tag of the response, and it wouldn't make any sense to be including body tags with AJAX responses.

Any direction would be helpful! Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Update: this functionality is now built into django-debug-toolbar

It was added in this PR and released in version 3.0


The old answer may still be useful for older versions of the toolbar:

I wrote the Request History Panel for Django Debug Toolbar that can be added to the Django Debug Toolbar to view requests other than the current one (including AJAX requests).

Install via pip:

pip install django-debug-toolbar-request-history

In settings.py add 'ddt_request_history.panels.request_history.RequestHistoryPanel' to DEBUG_TOOLBAR_PANELS e.g.:

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',
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...