Qucik Render Template Decorator with Contexts

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from decorator import decorator

@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))

More like this

  1. View decorator providing confirmation dialog by rudyryk 4 years, 2 months ago
  2. Quick-and-dirty decorator for static navigation context by pablo_PXL 3 years, 2 months ago
  3. render_to by asolovyov 5 years, 10 months ago
  4. View decorator to automate templates. by jafo 4 years, 2 months ago
  5. Decorate Template Tag (In-Line include and extend with local context) by rhomber 4 years, 3 months ago

Comments

(Forgotten your password?)