Replacing render_to_response with direct_to_template in Django
Update: September 3, 2012
A
render()
was introduced on Django 1.3 to useRequestContext
by default
You certainly have already used render_to_response
to render your templates, it’s a very convenient shortcut:
At least until you need to use context processors, then you start writing code like this
this context_instance
argument is the boilerplate code you will always need to make context processors work. I think it’s too much typing, and I’m lazy, so I prefer to use the direct_to_template
generic view:
You don’t need the context_instance
argument anymore, and you save one import.
But! There is one simple detail when passing extra context to this view, if a value in your dict is a callable, it will call and pass the result to template. It can be useful, but is something to keep in mind, if you’re trying to pass a callable to template.
Read the source code to understand how it works.