Edgewall Software

Version 1 (modified by cmlenz, 7 years ago) (diff)

Branch 0.5.x docs

Error: Macro Title(genshi.template.base) failed
pre-0.11 Wiki macro Title by provider <class 'Title.TitleMacro'> no longer supported


Basic templating functionality.


Base exception class for errors related to template processing.


Exception raised when an expression in a template causes a Python syntax error, or the template is not well-formed.


Exception raised when an unknown directive is encountered when parsing a template.

An unknown directive is any attribute using the namespace for directives, with a local name that doesn't match any registered directive.


Exception raised when an the evaluation of a Python expression in a template causes an error.


Container for template input data.

A context provides a stack of scopes (represented by dictionaries).

Template directives such as loops can push a new scope on the stack with data that should only be available inside the loop. When the loop terminates, that scope can get popped off the stack again.

>>> ctxt = Context(one='foo', other=1)
>>> ctxt.get('one')
>>> ctxt.get('other')
>>> ctxt.push(dict(one='frost'))
>>> ctxt.get('one')
>>> ctxt.get('other')
>>> ctxt.pop()
{'one': 'frost'}
>>> ctxt.get('one')

get(self, key, default=None)

Get a variable's value, starting at the current scope and going upward.

param key:the name of the variable
param default:the default value to return when the variable is not found


Return the name of all variables in the context.

return:a list of variable names


Return a list of (name, value) tuples for all variables in the context.

return:a list of variables

update(self, mapping)

Update the context from the mapping provided.

push(self, data)

Push a new scope on the stack.

param data:the data dictionary to push on the context stack.


Pop the top-most scope from the stack.


Meta class for templates.


Abstract template base class.

This class implements most of the template processing model, but does not specify the syntax of templates.

generate(self, **args, *kwargs)

Apply the template to the given context data.

Any keyword arguments are made available to the template as context data.

Only one positional argument is accepted: if it is provided, it must be an instance of the Context class, and keyword arguments are ignored. This calling style is used for internal processing.

return:a markup event stream representing the result of applying the template to the context data.

See Genshi XML Template Language, Genshi Text Template Language, ApiDocs/0.5.x, Documentation