1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 | {% if debug %}
<div id="debug">
<h2>Queries</h2>
<p>
{{ sql_queries|length }} Quer{{ sql_queries|pluralize:"y,ies" }}
{% ifnotequal sql_queries|length 0 %}
(<span style="cursor: pointer;" onclick="var s=document.getElementById('debugQueryTable').style;s.display=s.display=='none'?'':'none';this.innerHTML=this.innerHTML=='Show'?'Hide':'Show';">Show</span>)
{% endifnotequal %}
</p>
<table id="debugQueryTable" style="display: none;">
<col width="1"></col>
<col></col>
<col width="1"></col>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">SQL</th>
<th scope="col">Time</th>
</tr>
</thead>
<tbody>
{% for query in sql_queries %}<tr class="{% cycle odd,even %}">
<td>{{ forloop.counter }}</td>
<td>{{ query.sql|escape }}</td>
<td>{{ query.time }}</td>
</tr>{% endfor %}
</tbody>
</table>
</div>
{% endif %}
|
Comments
Thanks for the great snip! Wonderful tool for debugging 'slow pages'!
#
Cool!
I have little troubles with displaying long rows of queries. For example:
If you have a LOT of colX, they aren't wrapped in browser, and queries are bad to read.
So, I make little modification. I wrote custom filter, which replace character "," (comma) to ", " (comma and space). Now I could read debug SQL queries more comfortably.
My custom filter
Modification of your template (row 24)
Thank you for great snippet, insin.
#
thank you both insin for the snippet and msgre for the filter, however, i noticed a bug with the filter
the expression:
matches the first character after the comma (non-space), so after the sub call it is replacing that character with a space
i only caught this after realizing there was a missing " before each column
i swapped that out for:
and it seems to be working a-ok
#
I'm using this snippets with the modifications in the comments but I've found useful to add this templatetags:
and to restrict the number of queries printed like this:
Some of my views are used for validation and run up to a few hundred thousand queries, which is a bit too much to print in a browser.
#