Login

Renderer decorator

Author:
GaretJax
Posted:
November 28, 2007
Language:
Python
Version:
.96
Score:
0 (after 0 ratings)

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

  1. Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 3 months ago
  2. Python Django CRUD Example Tutorial by tuts_station 3 months, 2 weeks ago
  3. Browser-native date input field by kytta 4 months, 4 weeks ago
  4. Generate and render HTML Table by LLyaudet 5 months, 1 week ago
  5. My firs Snippets by GutemaG 5 months, 1 week ago

Comments

Please login first before commenting.