1 from django
.http
import HttpResponse
2 from django
.template
import RequestContext
3 from django
.template
.loader
import render_to_string
5 # with thanks to Peter Hunt (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/465427)
6 decorator_with_args
= lambda decorator
: lambda *args
, **kwargs
: lambda func
: \
7 decorator(func
, *args
, **kwargs
)
9 # with thanks to Robert Thomson (http://www.djangosnippets.org/snippets/459/)
11 def template_django(func
, template
=None):
12 def DJANGO_TEMPLATE(request
, *args
, **kwargs
):
13 res
= func(request
, *args
, **kwargs
)
18 return HttpResponse(render_to_string(template
, res
, RequestContext(request
)))
21 #return HttpResponse("Templating Error", status=500)
25 DJANGO_TEMPLATE
.__name
__ = func
.__name
__
26 DJANGO_TEMPLATE
.__doc
__ = func
.__doc
__
27 DJANGO_TEMPLATE
.__dict
__ = func
.__dict
__
28 return DJANGO_TEMPLATE