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
- Browser-native date input field by kytta 1 month, 1 week ago
- Generate and render HTML Table by LLyaudet 1 month, 2 weeks ago
- My firs Snippets by GutemaG 1 month, 3 weeks ago
- FileField having auto upload_to path by junaidmgithub 2 months, 4 weeks ago
- LazyPrimaryKeyRelatedField by LLyaudet 3 months, 1 week ago
Comments
Please login first before commenting.