Version 1 (modified by Alexander Solovyov <piranha@…>, 18 years ago) ( diff )

--

Code:

from django.shortcuts import render_to_response
from django.template import RequestContext

def render_to(tmpl):
    def renderer(func):
        def wrapper(request, *args, **kw):
            output = func(request, *args, **kw)
            if not isinstance(output, dict):
                return output
            return render_to_response(tmpl, output,
                                      context_instance=RequestContext(request))
        return wrapper
    return renderer

Usage:

@render_to('cool/template.html')
def view(request):
    if something:
        return HttpResponseRedirect('/')
    else:
        return {'people': people, 'things': things}
Note: See TracWiki for help on using the wiki.
Back to Top