Hey all,
I made this the other day to help me track all the sql statements my
pages were doing. I wanted something unobtrusive (i.e. middleware)
and simple. Hope you like:
from django.db import connection
import re, pprint
body_end = re.compile('</body>', re.IGNORECASE)
class DebugMiddleware(object):
def process_response(self, request, response):
if body_end.search(response.content) is not None:
db_info = pprint.pformat(connection.queries)
total = 0.0
for con in connection.queries:
total += float(con['time'])
response.content = body_end.sub('<pre>%s\nTotal:
%f</pre></body>' %
(db_info,total), response.content)
return response
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---