tempita package¶
A small templating language
This implements a small templating language. This language implements if/elif/else, for/continue/break, expressions, and blocks of Python code. The syntax is:
{{any expression (function calls etc)}}
{{any expression | filter}}
{{for x in y}}...{{endfor}}
{{if x}}x{{elif y}}y{{else}}z{{endif}}
{{py:x=1}}
{{py:
def foo(bar):
return 'baz'
}}
{{default var = default_value}}
{{# comment}}
You use this with the Template
class or the sub
shortcut.
The Template
class takes the template string and the name of
the template (for errors) and a default namespace. Then (like
string.Template
) you can call the tmpl.substitute(**kw)
method to make a substitution (or tmpl.substitute(a_dict)
).
sub(content, **kw)
substitutes the template immediately. You
can use __name='tmpl.html'
to set the name of the template.
If there are syntax errors TemplateError
will be raised.
-
exception
tempita.
TemplateError
(message, position, name=None)[source]¶ Bases:
exceptions.Exception
Exception raised while parsing a template
-
class
tempita.
Template
(content, name=None, namespace=None, stacklevel=None, get_template=None, default_inherit=None, line_offset=0, delimiters=None)[source]¶ Bases:
object
-
default_encoding
= 'utf8'¶
-
default_inherit
= None¶
-
default_namespace
= {'end_braces': '}}', 'looper': <class 'tempita._looper.looper'>, 'start_braces': '{{'}¶
-
-
class
tempita.
HTMLTemplate
(content, name=None, namespace=None, stacklevel=None, get_template=None, default_inherit=None, line_offset=0, delimiters=None)[source]¶ Bases:
tempita.Template
-
default_namespace
= {'attr': <function attr>, 'end_braces': '}}', 'html': <class 'tempita.html'>, 'html_quote': <function html_quote>, 'looper': <class 'tempita._looper.looper'>, 'start_braces': '{{', 'url': <function url>}¶
-