Skip to content

Instantly share code, notes, and snippets.

@devStepsize
Created April 12, 2016 16:23
Show Gist options
  • Save devStepsize/7bad81ee8aac0a6ed125461927baf380 to your computer and use it in GitHub Desktop.
Save devStepsize/7bad81ee8aac0a6ed125461927baf380 to your computer and use it in GitHub Desktop.
Useful template to show which queries are running to load a page. This requires the following steps first: 1.Have 'django.core.context_processors.debug' in your TEMPLATE_CONTEXT_PROCESSORS setting (it was there in the default settings, last time I checked). 2. Have your current IP in your INTERNAL_IPS setting. 3. Use RequestContext when renderin…
{% 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 %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment