Using mako templates

Uiro depends on mako template, and provide some shortcuts to use templates for applications. Templates for an application should store in yourpackage/templates directory. Uiro will collect templates and correlate the app and templates.

You learn how to use shortcuts here, but not about mako template usage. you should see mako documentation and learn about it.

Easiest way, by view

Most easiest way to get and render a template is specifying it by view_config, like this.

def get_view(self, request, context):
    entry = context['blog_entry']
    return {'entry': entry}

If views return a dictionary, view_config will handle it as context dictionary for a template specified by template_name. view_config will render it and use it as Response body.

You can specify a template by passing a template name that is string splittable by a colon. The left value is package name, and the right value is template name, like ‘blog:entry.mako’.

The template used in above example must be here:


It was collected automatically, so you can use it only specifying the signature.

Simplest way

You can get template by a getter function uiro.template.get_template. It simply returns mako template object, so you can render it by .render method.

from uiro.template import get_template
get_template('blog:entry.mako').render(entry='blog entry')

Table Of Contents

Previous topic

Connectiong to RDBs using SQLAlchemy

Next topic

Serving static files