tipfy.ext.genshi ¶
This extension provides Genshi templating support to tipfy. It is a port from Flask-Genshi, written by Dag Odenhall.
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.genshi 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.genshi'] = {
'templates_dir': 'my_template_directory',
}
GenshiMixin¶
A convenient way to render Genshi templates is to make RequestHandler extend GenshiMixin:
handlers.py
from tipfy import RequestHandler
from tipfy.ext.genshi import GenshiMixin
class MyHandler(RequestHandler, GenshiMixin):
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 variables.
Extension Reference¶
- Name: tipfy.ext.genshi
- Author: Dag Odenhall, Rodrigo Moraes (port to tipfy)
- License: BSD
- Tags: template engine, templates
- URL: http://www.tipfy.org/wiki/extensions/genshi/
- PyPi page: http://pypi.python.org/pypi/tipfy.ext.genshi/
- Source code: http://code.google.com/p/tipfy-ext-genshi/
- Issue tracker: http://code.google.com/p/tipfy-ext-genshi/issues/list
- Version: latest
- Edited by moraes on 7/20/10 7:54 PM
- Save on Delicious | Submit to Reddit
- History
- Edit
