Last active
August 29, 2015 14:19
-
-
Save 0atman/1912bfd62f8dbd93cfa5 to your computer and use it in GitHub Desktop.
A decorator to render the view with a template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render_to_response | |
def with_template(template): | |
""" | |
A decorator to render the view with a template. The view just | |
returns a contect dictionary. eg: | |
@with_template('index.html') | |
def index_view(request): | |
return {"name": "dave"} | |
""" | |
def template_decorator(view): | |
def view_wrapper(*args, **kwargs): | |
return render_to_response( | |
template, | |
view(*args, **kwargs) | |
) | |
return view_wrapper | |
return template_decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment