def render_to template def renderer func def wrapper request args kw o

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def render_to(template):
def renderer(func):
def wrapper(request, *args, **kw):
output = func(request, *args, **kw)
if isinstance(output, (list, tuple)):
return render_to_response(output[1], output[0], RequestContext(request))
elif isinstance(output, dict):
return render_to_response(template, output, RequestContext(request))
return output
return wrapper
return renderer
@render_to(index.html)
def index(request):
catalogs = Catalog.objects.all()
return {'catalogs': catalogs,
'top':Product.objects.filter(in_top=True),
'user':request.user,}