Question

I want to write a middleware that would tell me the name of the template being rendered and the time it took, for the database queries for that particular view. Django Debug Toolbar does the same, but due to custom request and response object written i am not able to get that working. So i thought of writing a custom middleware that would do the same for me on a url appended with some get request variable.
Say 127.0.0.1/index/polls gives me all the polls. If i try 127.0.0.1/index/polls/?my_tool it would invoke a url, and i would get the data.

Any suggestions on how to implement it? Is there a working example?

Was it helpful?

Solution

I could infer that you need some debug tool for development, in that case I would suggest django-debug-toolbar, otherwise, if you really need the middleware you always can look at the code of django-debug-toolbar. :)

If I´ve got to write that by myself, I would write a couple of classes (in debug toolbar are called panels) that inherits from template and timer, and override the method process_response for log or print the info that I need.

Even you can look into the middleware of debug-toolbar and picture an idea of how it works

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top