curly.template

This module contains an implementation of template.

The main idea of the template is to run parsing of the text and store AST tree, the result of the parsing. Also, it has a reference to the environment. This is required for running of rendering routine.

class curly.template.Template(text)[source]

Bases: object

Template stored parsed and ‘compiled’ template.

Using this class, you can render the template for different contexes without reparsing it each time.

Parameters:text (str or bytes) – A template to compile.
Raises:ValueError – if it is not possible to convert text into AST tree.
render(context)[source]

Render template into according to the given context.

Parameters:context (dict) – A dictionary with variables for the template.
Returns:Rendered template
Return type:str
Raises:ValueError – if it is not possible to render template with the given context.