- Author:
- joshua
- Posted:
- February 28, 2007
- Language:
- Python
- Version:
- Pre .96
- Score:
- 4 (after 4 ratings)
This middleware will add a log of the SQL queries executed at the bottom of every page. You can (should) use BeautifulSoup to place this in a specific location.
Note: If you serve non-html content, it would be wise to do a mimetype check.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | from django.db import connection
from django.template import Template, Context
class SQLLogMiddleware:
def process_response ( self, request, response ):
t = Template('''
<ul class="sqllog">
{% for sql in sqllog %}
<li>{{ sql.sql }}</li>
{% endfor %}
</ul>
''')
response.content = "%s%s" % ( response.content, t.render(Context({'sqllog':connection.queries})))
|
More like this
- Generate and render HTML Table by LLyaudet 5 days, 7 hours ago
- My firs Snippets by GutemaG 1 week, 1 day ago
- FileField having auto upload_to path by junaidmgithub 1 month, 2 weeks ago
- LazyPrimaryKeyRelatedField by LLyaudet 1 month, 3 weeks ago
- CacheInDictManager by LLyaudet 1 month, 3 weeks ago
Comments
this worked great but I had to add the following line to return a response
...
response.content = "%s%s" % ( response.content, t.render(Context({'sqllog':connection.queries})))
return response
#
I improved Snippet 161 in Snippet 344.
It counts duplicated SQL queries.
#
Please login first before commenting.