Skip to content

Instantly share code, notes, and snippets.

@imflop
Created October 11, 2014 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imflop/2d0c99347c137446d739 to your computer and use it in GitHub Desktop.
Save imflop/2d0c99347c137446d739 to your computer and use it in GitHub Desktop.
Django render to response decorator
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment