Log in

tipfy.ext.mako

This extension provides Mako templating support to tipfy.

Usage is very simple: you simply need to import render_template or render_response from the extension module, passing the template filename you want to render and keyword arguments to be used in the template.

handlers.py

from tipfy import RequestHandler
from tipfy.ext.mako import render_response

class MyHandler(RequestHandler):
    def get(self, **kwargs):
        return render_response('hello_world.html', message='Hello, World!')

Templates are by default loaded from the templates directory from your application root. You can change this in the configuration:

config.py

config['tipfy.ext.mako'] = {
    'templates_dir': 'my_template_directory',
}

MakoMixin

A convenient way to render Mako templates is to make RequestHandler extend MakoMixin:

handlers.py

from tipfy import RequestHandler
from tipfy.ext.mako import MakoMixin

class MyHandler(RequestHandler, MakoMixin):
    def get(self, **kwargs):
        return self.render_response('hello_world.html', message='Hello, World!')

In this case, request context variables are also passed to the template. Keyword arguments passed to self.render_response() override request context variables.

Extension Reference


Powered by Moe. Yeah, the name is Moe. Powered by Google App Engine