| | 1 | '''Code:''' |
| | 2 | {{{ |
| | 3 | from django.shortcuts import render_to_response |
| | 4 | from django.template import RequestContext |
| | 5 | |
| | 6 | def 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') |
| | 21 | def view(request): |
| | 22 | if something: |
| | 23 | return HttpResponseRedirect('/') |
| | 24 | else: |
| | 25 | return {'people': people, 'things': things} |
| | 26 | }}} |