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. My firs Snippets by GutemaG 3 days, 3 hours ago
  2. FileField having auto upload_to path by junaidmgithub 1 month, 1 week ago
  3. LazyPrimaryKeyRelatedField by LLyaudet 1 month, 2 weeks ago
  4. CacheInDictManager by LLyaudet 1 month, 2 weeks ago
  5. MYSQL Full Text Expression by Bidaya0 1 month, 2 weeks ago

Comments

Please login first before commenting.