On 12 Jan 2006, at 07:23, Amit Upadhyay wrote:
Another request: if debug is on, and if the url contains ? dumpTemplateContext, and client IP in settings.trusted_hosts [and blah blah blah depending on how paranoid you are], render_to_response, and family, ignores the actual template, and instead dumpts the context variable passed, and detailed instuctions about their type, and some comment on how to loop if the variable is list like and so on. This is meant to be used by the designers who would be creating template, so it can contain a link to tutorial, or dump the tutorial and faq and everything, anything to make the job of designer easier.
This could almost be done right now using middleware, without any changes to Django proper. If the middleware proved useful enough it could then be rolled in to Django proper.
The thing holding back a middleware implementation is the decoupling of response objects and the template system. The middleware would have to intercept the HttpResponse object returned by the view function and extract the template and context from it, but by that point the template has been rendered in to a string.
This isn't the only case where being able to introspect in to the template and context used during a request would be useful. The other obvious use case is writing unit tests - a Django application test harness would benefit greatly from the ability to run a view function with certain parameters and then inspect the template, context and HttpResponse object produced by that view.
I'm certainly not suggesting we couple HttpResponse to the template library, but is there some kind of middle ground? I know we use crazy stack tracing hacks already for the fancy error pages but that seems like a bit of a hack. Maybe we could do something with PyDispatcher - maybe t.render(c) could fire a "template A has been rendered with context B" event which other bits of code (related to dynamic view documentation and/or unit testing) could listen out for.
Is there a better way of solving this problem? Cheers, Simon
