RenderTemplate

Render on the target through a connection. render_file reads a path on that target. See Templating for syntax and local rendering.

class rmote.tools.template.RenderTemplate[source]

Bases: Tool

Built-in tool that renders Jinja-like templates with restricted expressions.

Both methods execute on the remote process. See Templating for a full description of the template syntax.

Render locally, then send the compiled template to another Python process:

>>> from rmote.templates import Template
>>> from rmote.sync import Connection
>>> from rmote.tools import RenderTemplate
>>> Template("Hello, {{ name }}!").render(name="Ada")
'Hello, Ada!'
>>> compiled = Template("port={{ port }}")
>>> with Connection.from_local() as remote:
...     rendered = remote(RenderTemplate.render, compiled, port=8080)
>>> rendered
'port=8080'
>>> RenderTemplate.render("{% for name in names %}[{{ name }}]{% endfor %}", names=["web", "db"])
'[web][db]'
static render(template, **kwargs)[source]

Render source text or a compiled template with the supplied values.

Source strings are compiled on the receiving host. A supplied Template transfers its intermediate representation and filter classes, and renders without recompilation.

Parameters:
  • template (Text | Template) – Source string or a compiled template instance.

  • **kwargs (object) – Variables available inside the template.

Return type:

Text

Returns:

The rendered string.

static render_file(path, **kwargs)[source]

Read the template file at path on the remote host and render it.

Parameters:
  • path (Text | Path) – Absolute path to the remote template file, as a string or Path.

  • **kwargs (object) – Variables available inside the template.

Return type:

Text

Returns:

The rendered string.