mirror of
https://github.com/fergalmoran/dss.api.git
synced 2025-12-22 17:28:55 +00:00
27 lines
781 B
Python
27 lines
781 B
Python
from decorator import decorator
|
|
from django.http import HttpResponseRedirect
|
|
from django.shortcuts import render_to_response
|
|
from django.template.context import RequestContext
|
|
|
|
@decorator
|
|
def render_template(func, *args, **kwargs):
|
|
"""
|
|
using example:
|
|
@render_template
|
|
def view(request, template='abc.html'):
|
|
slot = "this is a slot"
|
|
return template, {'slot' : slot}
|
|
"""
|
|
request = args[0]
|
|
_call = func(*args, **kwargs)
|
|
|
|
if isinstance(_call, HttpResponseRedirect):
|
|
return _call
|
|
|
|
if isinstance(_call, tuple):
|
|
template, context = _call
|
|
else:
|
|
template, context = _call, {}
|
|
|
|
return render_to_response(template, context_instance=RequestContext(request, context))
|