Django snippet for automating templates. (tummy.com, ltd. Journal Entry)
tummy.com: we do linux

Tuesday February 02, 2010 at 21:04
Subject: Django snippet for automating templates.
Keywords: Django, Python
Posted by: Sean Reifschneider

I just posted a Django snippet that (ab)uses a decorator to change how you call templates in Dango views. For example, it makes my view code something like this:

####################################
@with_template('friends/index.html')
def friends(request, context, username):
   context['user'] = User.objects.get(username = username)

And the view:

{% extends "base.html" %}
{% block content %}
<h1>{{ user.username }}'s Friends</h1>

(Post Reply)