1👍
This doesn’t even vaguely make sense. You want to measure the time taken to perform the queries in a response. Naturally, you put it in the process_response
middleware method, which is triggered after the response has been processed. But then somehow you expect that data to be available in the template you’ve just rendered? How could that possibly work?
Even if you did alter this to use process_template_response
as Bruce suggests (and you’d also need to use a TemplateResponse rather than a normal response) that still wouldn’t work, as although you then would have access to the data, it would be totally inaccurate since it wouldn’t measure any of the queries that were made in the template rendering stage itself. Remember that Django querysets are lazy and are not actually executed until they are iterated, so most database work tends to happen within the template rendering process.
In any case, if you want to see data on your queries, you should use the Django debug toolbar.
0👍
I think you want to use process_template_response (https://docs.djangoproject.com/en/1.6/topics/http/middleware/#process-template-response) instead of the process_response. The latter is called after the template was already processed, so it is too late.