Template#
- class caf.viz.web.mapping.Template(source, block_start_string='{%', block_end_string='%}', variable_start_string='{{', variable_end_string='}}', comment_start_string='{#', comment_end_string='#}', line_statement_prefix=None, line_comment_prefix=None, trim_blocks=False, lstrip_blocks=False, newline_sequence='\n', keep_trailing_newline=False, extensions=(), optimized=True, undefined=<class 'jinja2.runtime.Undefined'>, finalize=None, autoescape=False, enable_async=False)#
Bases:
objectA compiled template that can be rendered.
Use the methods on
Environmentto create or load templates. The environment is used to configure how templates are compiled and behave.It is also possible to create a template object directly. This is not usually recommended. The constructor takes most of the same arguments as
Environment. All templates created with the same environment arguments share the same ephemeralEnvironmentinstance behind the scenes.A template object should be considered immutable. Modifications on the object are not supported.
Attributes
The debug info mapping.
If this variable is False there is a newer version available.
The template as module.
Methods
from_code(environment, code, globals[, uptodate])Creates a template object from compiled code and the globals.
from_module_dict(environment, module_dict, ...)Creates a template object from a module.
generate(*args, **kwargs)For very large templates it can be useful to not render the whole template at once but evaluate each statement after another and yield piece for piece.
generate_async(*args, **kwargs)An async version of
generate().get_corresponding_lineno(lineno)Return the source line number of a line number in the generated bytecode as they are not in sync.
make_module([vars, shared, locals])This method works like the
moduleattribute when called without arguments but it will evaluate the template on every call rather than caching it.make_module_async([vars, shared, locals])As template module creation can invoke template code for asynchronous executions this method must be used instead of the normal
make_module()one.new_context([vars, shared, locals])Create a new
Contextfor this template.render(*args, **kwargs)This method accepts the same arguments as the dict constructor: A dict, a dict subclass or some keyword arguments. If no arguments are given the context will be empty. These two calls do the same::.
render_async(*args, **kwargs)This works similar to
render()but returns a coroutine that when awaited returns the entire rendered template string.stream(*args, **kwargs)Works exactly like
generate()but returns aTemplateStream.Attributes Documentation
- Parameters:
source (str | Template)
block_start_string (str)
block_end_string (str)
variable_start_string (str)
variable_end_string (str)
comment_start_string (str)
comment_end_string (str)
line_statement_prefix (str | None)
line_comment_prefix (str | None)
trim_blocks (bool)
lstrip_blocks (bool)
newline_sequence (te.Literal['\n', '\r\n', '\r'])
keep_trailing_newline (bool)
optimized (bool)
undefined (Type[Undefined])
enable_async (bool)
- Return type:
- debug_info#
The debug info mapping.
- is_up_to_date#
If this variable is False there is a newer version available.
- module#
The template as module. This is used for imports in the template runtime but is also useful if one wants to access exported template variables from the Python layer:
>>> t = Template('{% macro foo() %}42{% endmacro %}23') >>> str(t.module) '23' >>> t.module.foo() == u'42' True
This attribute is not available if async mode is enabled.
- environment: Environment#
- globals: MutableMapping[str, Any]#