Rendering Jinja2 template for email

670 views
Skip to first unread message

Bert

unread,
Feb 6, 2012, 9:33:40 AM2/6/12
to tipfy
Hi,

I'm using 1.01b and I want to render Jinja2 template that will be sent
in an email.
I'm not sending the email from within a request handler (so I don't
have self.render_template). Looking at tipfyext.jinja2 there is Jinja2
class which I could create an instance of, but how do I access the
"app" parameter that it requires?

Thanks
Rob

Bert

unread,
Feb 6, 2012, 9:42:21 AM2/6/12
to tipfy
I fiddled around a bit more and have it working, but not sure whether
it's correctly implemented.

from tipfyext.jinja2 import Jinja2
from tipfy import Tipfy
from config import config

def render_email_template(file, **context):
app = Tipfy(config=config)
jinja2 = Jinja2(app)
return jinja2.render(file, **context)

comments?
Reply all
Reply to author
Forward
0 new messages