Request context processors - shortcut

2 views
Skip to first unread message

spako

unread,
Jul 11, 2006, 3:19:55 PM7/11/06
to Django users
i'm going to be using custom context processors a lot so i've written
my own shortcut to invoke RequestContext and get a template rendered.
this is my function:

def render_to_response_with_context_processors(template_name, request,
args={}):
"""
this function was written to provide a "shortcut" when using
context processors
if i use this a lot i'll come up with a better (shorter) name
"""
t = template_loader.get_template(template_name)
c = RequestContext(request, args)
return HttpResponse(t.render(c))

this is the only way i could get context processors specified in the
setting TEMPLATE_CONTEXT_PROCESSORS to be run in a view. i basically
want to know if what i do is the "correct" way of doing things and also
if there are other way of getting context processors to run. (i.e. not
having to invoke RequestContext)?

James Bennett

unread,
Jul 11, 2006, 3:26:29 PM7/11/06
to django...@googlegroups.com
On 7/11/06, spako <tran...@gmail.com> wrote:
> this is the only way i could get context processors specified in the
> setting TEMPLATE_CONTEXT_PROCESSORS to be run in a view. i basically
> want to know if what i do is the "correct" way of doing things and also
> if there are other way of getting context processors to run. (i.e. not
> having to invoke RequestContext)?

render_to_response takes an optional 'context_instance' argument which
can tell it to use RequestContext or any other subclass of Context you
might have defined, instead of the default.

--
"May the forces of evil become confused on the way to your house."
-- George Carlin

spako

unread,
Jul 11, 2006, 3:45:55 PM7/11/06
to Django users
Thanks, that's exaclty what i needed!

Reply all
Reply to author
Forward
0 new messages