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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.