Changes between Initial Version and Version 1 of CookBookShortcutsPageDecoratorSimple


Ignore:
Timestamp:
Feb 19, 2007, 8:43:07 AM (18 years ago)
Author:
Alexander Solovyov <piranha@…>
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CookBookShortcutsPageDecoratorSimple

    v1 v1  
     1'''Code:'''
     2{{{
     3from django.shortcuts import render_to_response
     4from django.template import RequestContext
     5
     6def render_to(tmpl):
     7    def renderer(func):
     8        def wrapper(request, *args, **kw):
     9            output = func(request, *args, **kw)
     10            if not isinstance(output, dict):
     11                return output
     12            return render_to_response(tmpl, output,
     13                                      context_instance=RequestContext(request))
     14        return wrapper
     15    return renderer
     16}}}
     17
     18'''Usage:'''
     19{{{
     20@render_to('cool/template.html')
     21def view(request):
     22    if something:
     23        return HttpResponseRedirect('/')
     24    else:
     25        return {'people': people, 'things': things}
     26}}}
Back to Top