You can use this as a decorator for your views, this way you can return a simple dictionary and the decorator will do the rest.
@TODO: Automatically set the template based on the app/view request
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | from django.shortcuts import render_to_response
def render(template):
def render_view(view):
def data_to_render(request, *args, **keys):
return render_to_response(template.replace('.', '/') + '.html', view(request, *args, **keys))
return data_to_render
return render_view
# Example:
# @render('blog.article_list') # The template to use
# def article_list(request):
# return { # The data to render
# 'article': Article.objects.all(),
# 'url': 'http://garetjax.info/',
# }
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.