views:

24

answers:

1

How can I measure time taken for template generation?
I know i can collect time Context.render() takes but can i do it unobtrusive way? Something like Page Stats Middleware do for Python and DB time... But split Python time to code/view time and template time?

+1  A: 

You could swap old render method to your own like this:

old_render = Context.render

def new_render(self, *args, **kwargs):
  # do some profiling
  old_render(self, *args, **kwargs)
  # do some profiling

Context.render = new_render

This shouldn't be very obtrusive and you can remove it anytime you won't - it doesn't change interface.

I don't believe you can use middleware, because middleware works before request is passed to a view - and you render a template inside a view.

gruszczy
you are right... my bad ) too many coffee i think.
NilColor
Hope this helps :-)
gruszczy