本文整理汇总了Python中jinja2.runtime.Context方法的典型用法代码示例。如果您正苦于以下问题:Python runtime.Context方法的具体用法?Python runtime.Context怎么用?Python runtime.Context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.runtime
的用法示例。
在下文中一共展示了runtime.Context方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_context
# 需要导入模块: from jinja2 import runtime [as 别名]
# 或者: from jinja2.runtime import Context [as 别名]
def new_context(self, vars=None, shared=False, locals=None):
"""Create a new :class:`Context` for this template. The vars
provided will be passed to the template. Per default the globals
are added to the context. If shared is set to `True` the data
is passed as it to the context without adding the globals.
`locals` can be a dict of local variables for internal usage.
"""
return new_context(self.environment, self.name, self.blocks,
vars, shared, self.globals, locals)
示例2: get_id
# 需要导入模块: from jinja2 import runtime [as 别名]
# 或者: from jinja2.runtime import Context [as 别名]
def get_id(context: Context, prefix: str) -> str:
"""
A jinja2 context filter for creating reusable unique identifiers within a
cauldron display. The uid is designed to be unique within each step within
a project, as well as unique each time that step is rendered. A UID is
made up of three pieces::
cdi-[PREFIX]-[RENDER_HASH]
The "cdi" is a universal prefix that prevents any possible collision with
non-cauldron IDs in the page. The [PREFIX] is supplied by the prefix
argument to separate different IDs inside the same render step. The
[RENDER_HASH] is a unique character string that is created uniquely each
time a render step completes.
:param context:
Jinja2 context in which this filter is being applied
:param prefix:
Prefix string that indicates which uid is being created within a step
:return:
A uniquely identifying string.
"""
return 'cdi-{}-{}'.format(
prefix,
context['cauldron_template_uid']
)
示例3: get_latex
# 需要导入模块: from jinja2 import runtime [as 别名]
# 或者: from jinja2.runtime import Context [as 别名]
def get_latex(content:Context, prefix: str) -> str:
"""..."""
return '\n\n{}\n\n'.format(render_template(
'katex.html',
source=utils.format_latex(prefix)
))