{% 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.
#
Very helpful snippen. Tanks.
By the way... in current Django SVN version You don't have to set TEMPLATE_CONTEXT_PROCESSORS, it's on by default.
#
Brilliant works like a charm :)
af
#
Awesome snippet. Simple, clean, and effective...
#
Hello,
I am new to django and i justed started to play around with django. I've copied this snippet to my base template but I can't see anything?
I checked every of the three steps mentioned above, the context processors are set by default and my ip is on INTERNAL_IPS. I don't understand what the third point means but I've added a request context to shortcut for rendering templates.
What can I do to get it work? Thanks for your help in advance and sorry for my bad english.
analyzer
#
nice !
#
Do you acknowledge that it's high time to receive the personal loans, which will realize your dreams.
#
I often find something like this lurking at the end of my base templates iPad 2 Cases
#
Very useful
Latisse UK
#
Thanks for the snippet. It'll come in handy! Kevin's website.
#
Do you acknowledge that it's high time to receive the personal loans, which will realize your dreams. auto insurance rates
#
Oh yes thanks for this research. [HTML_REMOVED]coque iphone[HTML_REMOVED]
#
I often find something like this lurking at the end of my base templates james insurance blog
#
Very awesome snippets, clean and simple. Thanks. All Home Theater
#
I still can't get it to work. I'm using Django 1.3.1. Can someone post their settings? I had to add a number of options to TEMPLATE_CONTEXT_PROCESSORS to get my site to render correctly. ("django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.static", "django.contrib.messages.context_processors.messages")
I'm not clear where the template code goes. I copied it into my admin_base.html.
#
Ok,Just Test
#
Dengan definisi yang luas dari seni, tips cepat hamil [7] karya seni telah ada selama hampir sepanjang manusia: dari pra-sejarah seni awal untuk seni kontemporer, namun beberapa teori membatasi konsep untuk masyarakat Barat modern [9] Yang soal ulangan sd pertama dan luas. rasa seni adalah salah satu yang tetap dekat dengan tua Latin yang berarti, yang secara kasar diterjemahkan menjadi "keterampilan" atau "kerajinan." Beberapa contoh di mana ini berarti membuktikan sangat luas termasuk artefak, buatan, kecerdasan, seni medis, militer dan seni. Namun, belajar bahasa inggris ada banyak kegunaan sehari-hari lainnya kata, semua dengan beberapa hal yang etimologi.
#
Pendidikan kursus bahasa inggris murah Adat mengacu pada pencantuman pengetahuan adat, model, metode dan konten dalam sistem pendidikan formal dan non-formal. Seringkali dalam konteks pasca-kolonial, pengakuan tumbuh dan dimana lagi penggunaan metode pendidikan adat dapat menjadi respon terhadap erosi dan hilangnya pengetahuan adat dan bahasa melalui proses kolonialisme. Selain itu, dapat memungkinkan masyarakat kursus teknisi komputer adat untuk "merebut kembali dan merevaluasi bahasa dan budaya mereka, dan dengan demikian, meningkatkan keberhasilan pendidikan siswa pribumi." [9]
#
Exactly what I want! Thanks for the great snip! Wonderful tool for debugging 'slow pages'!
SuplemenFitness.net
#
Nice Blog definitely, you will find a many approaches after visiting your post.This is good to hear that finally, they come up with this innovation.El&Font font [HTML_REMOVED]Jual Obat Kuat[HTML_REMOVED] situation as well as the environment ,[HTML_REMOVED]Obat diabetes[HTML_REMOVED] but not so that we endure it , to live actively. John, I've just back from
#
Thanks [HTML_REMOVED]cara cepat hamil[HTML_REMOVED] for your great article friend,[HTML_REMOVED]CARA BELAJAR BAHASA INGGRIS[HTML_REMOVED] i get new information,[HTML_REMOVED]margahayuland[HTML_REMOVED] new ideas to do somethings,[HTML_REMOVED]how to get rid of acne home remedies[HTML_REMOVED] i hope you will share again, [HTML_REMOVED]the best acne treatment[HTML_REMOVED] i keep waiting for next post, thanks.[HTML_REMOVED]how to lose weight fast easy[HTML_REMOVED]
#
http://grosirjamtanganonline.com http://howtogetridofacnehomeremedies.org http://carabelajarbisnisonline.org http://carabelajarbahasainggris.net http://tipscaracepathamil.org/tips-cara-cepat-punya-anak http://tipscaracepathamil.org/cara-mudah-hamil-dengan-berolahraga http://tipscaracepathamil.org/penyebab-infertilitas-pada-wanita
#
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles.
agen sbobet, Judi, Modifikasi, Bokep Streaming, Casino, Poker
#
Part of my job requires me to stay on top of this subject. The article you have written has been beneficial in my research. Thanks a lot. Jasa seo, Ghantoby
#
Thanks for a very interesting web site. Where else could I get that kind of info written in such an ideal approach? I have a undertaking that I'm just now working on, and I've been at the look out for such information. Jasa seo
#