Genshi renderer for lribeiro.cherrypy.templating
Project description
Genshi renderer for lribeiro.cherrypy.templating
It has three optional config entries:
templating.genshi.template_directories: can be a path to the templates directory, list of paths, or anything genshi.template.TemplateLoader accepts. If none is given, {root module directory}/templates is used as the template diretory.
templating.genshi.loader_options: dict containing additional arguments passed to the TemplateLoader constructor
templating.genshi.render_options: dict containing arguments used when rendering the template, for example, {‘method’: ‘html’, ‘doctype’: ‘html-transitional’}
You can also pass arguments to the render via @template decorator args and kwargs.
class Controller:
@cherrypy.expose
@template('template_name.html', method='xhtml', doctype='xhtml11')
def handler(self):
pass
When setting the template name, remember that Genshi interprets a leading slash as an absolute path! So the following would probably raise a TemplateNotFound:
class WrongController:
@cherrypy.expose
# pay attention to the leading slash
# Genshi will look for a 'wrong_template_name.html' file on the root of the filesystem
@template('/wrong_template_name.html')
def wrong_handler(self):
pass
Developed under Python3.4 and tested against Python2.7, Python3.4 and pypy.
Usage:
import cherrypy
from lribeiro.cherrypy.templating import template
from lribeiro.cherrypy.templating.genshi import renderer
class Root(object):
@cherrypy.expose
@template('index.html')
def index(self):
return {'context': 'variables'}
@cherrypy.expose
@template('/var/templates/page.html') # absolute path
def page(self):
return {'context': 'variables'}
config = {
'/': {
'templating.renderer': renderer,
'templating.genshi.template_directories': [
'templates', # relative to the module where the root class was declared
'/var/templates' # absolute path
],
'templating.genshi.loader_options': {'default_encoding': 'utf-8'}, # this is optional
'templating.genshi.render_options': {'method': 'html', 'doctype': 'html5'} # this is also optional
}
}
if __name__ == '__main__':
cherrypy.quickstart(Root(), '/', config)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lribeiro.cherrypy.templating.genshi-1.0.tar.gz
.
File metadata
- Download URL: lribeiro.cherrypy.templating.genshi-1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
4586d0172216a1a78512cb3f6dca7b04ceda3e1f6d456be97e8d21fe4faf29b8
|
|
MD5 |
912f06e65a0f4515c1bab2b6207f38fe
|
|
BLAKE2b-256 |
15ea2e815e1dfd7b126c1195712bd5795e3362033995b831ab6bd393480c8da5
|
File details
Details for the file lribeiro.cherrypy.templating.genshi-1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: lribeiro.cherrypy.templating.genshi-1.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
2a0e57b604f9763d42199fc901af9bbd1a56d87bccb4b44bd1e68fe7e078f4dc
|
|
MD5 |
0336240861792dfe4effc7f1aaf5ef7a
|
|
BLAKE2b-256 |
ce75b6e198892c16cdf81c2efc6d08860ccca592d70ad43fe445cb167b9957a6
|