Login

render_with decorator

Author:
tobias
Posted:
September 4, 2008
Language:
Python
Version:
1.0
Score:
1 (after 3 ratings)

Automatically render your view using render_to_response with the given template name and context, using RequestContext (if you don't know what this is you probably want to be using it). For example:

@render_with('books/ledger/index.html')
def ledger_index(request):
    return {
        'accounts': ledger.Account.objects.order_by('number'),
    }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from django.shortcuts import render_to_response
from django.template import RequestContext

def render_with(template):
    def render_with_decorator(view_func):
        def wrapper(*args, **kwargs):
            request = args[0]
            context = view_func(*args, **kwargs)
            return render_to_response(
                template, 
                context, 
                context_instance=RequestContext(request),
            )
        return wrapper
    return render_with_decorator

More like this

  1. Treat empty value on DateRangeFilter as a filter for non filled dates by kmmbvnr 1 month ago
  2. Django Settings Assignment Expressions aka Walrus Operator example by webology 2 months ago
  3. codigo alto nivel by MrRocklion 4 months ago
  4. Load template from specific app by Krzysiek555 4 months, 2 weeks ago
  5. PostgreSQL JSON subqueries by dolamroth 4 months, 3 weeks ago

Comments

Please login first before commenting.