render_to_response wrapper

1
2
3
4
5
6
from django.shortcuts import render_to_response
from django.template import RequestContext

def render_response(req, *args, **kwargs):
    kwargs['context_instance'] = RequestContext(req)
    return render_to_response(*args, **kwargs)

Comments

whiteinge (on June 27, 2007):

As mentioned by Russell Keith-Magee, this is pretty much the same thing as Django's direct_to_template Generic View.

from django.views.generic.simple import direct_to_template

def my_view(self):
    return direct_to_template(request, 'my_template.html', {
        'extra-context': 'goes here',
    })

#

stereoit (on July 18, 2007):

+1 from me as I do not have to pass the RequestContext all the time, specially handy for newbie. I spent some time debugging why the authentication is not persistent across the requests just to find out I forgot add RequestContext.

with previous comment I stil lhave to use:

return direct_to_template(request, 'template' , {'context_instance':RequestContext(request), 'form':form})

right?

#

stereoit (on July 18, 2007):

fix to my previous comment, I didn't catch that the RequestContext is in the return statement of direct_to_template. So indeed it looks like this snippet is already in django in some way ;)

#

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.