Cha*_*her 52 python django django-debug-toolbar
我很好奇是否有合理的方法来使用(惊人的)django-debug-toolbar和AJAX查询.
例如,我使用带有一堆参数的jQuery $ .get来命中Django URL并将其加载到内联中.如果我有错误,它不会在工具栏上注册.我也不能通过复制AJAX URL来使用它,因为DDT附加到响应的body标签,并且包含具有AJAX响应的body标签没有任何意义.
任何方向都会有所帮助!谢谢!
rec*_*hak 35
我之前遇到过同样的问题!当我正在做越来越多的AJAX繁重的应用程序时,我发布了一个Django应用程序和一个Chrome扩展程序,它们共同解决了这个问题.
所有信息都在github存储库中.
djs*_*tho 17
我编写了Django调试工具栏的请求历史记录面板,可以将其添加到Django调试工具栏中以查看当前请求之外的请求(包括AJAX请求).
通过pip安装:
pip install django-debug-toolbar-request-history
Run Code Online (Sandbox Code Playgroud)
在settings.py中添加'ddt_request_history.panels.request_history.RequestHistoryPanel'到DEBUG_TOOLBAR_PANELS例如:
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',
]
Run Code Online (Sandbox Code Playgroud)
我最近遇到了这个问题.我的快速肮脏但工作的解决方案只是添加一些HTML视图来灵活地使用相同的代码.
例如,如果我可以在NewRelic中看到我的网站90%的时间用于对/ search_for_book?title =的ajax调用,我的代码可能如下所示:
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)
Run Code Online (Sandbox Code Playgroud)
瓶颈将出现在_search_for_book代码中; 我们是否用ajax调用它与诊断效率低下无关(在我的例子中,至少是YMMV)
| 归档时间: |
|
| 查看次数: |
11556 次 |
| 最近记录: |