Sharing Jinja2 templates between Pylons and Django applications
Posted
by Joe Holloway
on Stack Overflow
See other posts from Stack Overflow
or by Joe Holloway
Published on 2010-06-04T21:55:04Z
Indexed on
2010/06/17
19:53 UTC
Read the original article
Hit count: 297
I'm writing a couple of Jinja2 templates that basically implement some common grid layouts. I'd like to be able to share this 'library' of templates between a Pylons app and Django app.
I've hit a minor stumbling block in that Django's template context is accessible from the "top-level" of the template, whereas Pylons wraps your context inside the thread local c
(or tmpl_context
) variable.
Here are some analogous examples that demonstrate this.
Django
from django.shortcuts import render_to_response
ctx = {}
ctx['name'] = 'John'
return render_to_response('hello.html', ctx)
hello.html:
Hello {{ name }}
Pylons
from pylons import tmpl_context as c
from myapp.lib.base import render
c.name = 'John'
return render('hello.html')
hello.html:
Hello {{ c.name }}
What I'm trying to do is make it so that hello.html
is the same across both frameworks.
One way I see to do it is by wrapping the Django render_to_response
and do something like this:
ctx['c'] = ctx
But that just doesn't feel right. Anybody see other alternatives to this?
Thanks
© Stack Overflow or respective owner