Undocumented
Class |
|
Cycle through values by yield them one at a time, then restarting once the end is reached. Available as ``cycler`` in templates. |
Class |
|
A joining helper for templates. |
Class |
|
A simple LRU Cache implementation. |
Class |
|
A namespace object that can hold arbitrary attributes. It may be initialized from a dictionary or with keyword arguments. |
Function | clear |
Jinja keeps internal caches for environments and lexers. These are used so that Jinja doesn't have to recreate environments and lexers all the time. Normally you don't have to care about that but if you are measuring memory consumption you may want to clean the caches. |
Function | consume |
Consumes an iterable without doing anything with it. |
Function | generate |
Generate some lorem ipsum for the template. |
Function | htmlsafe |
Serialize an object to a string of JSON with :func:`json.dumps`, then replace HTML-unsafe characters with Unicode escapes and mark the result safe with :class:`~markupsafe.Markup`. |
Function | import |
Imports an object based on a string. This is useful if you want to use import paths as endpoints or something similar. An import path can be specified either in dotted notation (``xml.sax.saxutils.escape``) or with a colon as object delimiter (``xml... |
Function | internalcode |
Marks the function as internally used |
Function | is |
Check if the object passed is undefined. This does nothing more than performing an instance check against :class:`Undefined` but looks nicer. This can be used for custom filters or tests that want to react to undefined variables... |
Function | object |
Returns the name of the object's type. For some recognized singletons the name of the object is returned instead. (For example for `None` and `Ellipsis`). |
Function | open |
Returns a file descriptor for the filename if that file exists, otherwise ``None``. |
Function | pass |
Pass the :class:`~jinja2.runtime.Context` as the first argument to the decorated function when called while rendering a template. |
Function | pass |
Pass the :class:`~jinja2.Environment` as the first argument to the decorated function when called while rendering a template. |
Function | pass |
Pass the :class:`~jinja2.nodes.EvalContext` as the first argument to the decorated function when called while rendering a template. See :ref:`eval-context`. |
Function | pformat |
Format an object using :func:`pprint.pformat`. |
Function | select |
Intelligently sets the initial value of autoescaping based on the filename of the template. This is the recommended way to configure autoescaping if you do not want to write a custom function yourself. |
Function | url |
Quote a string for use in a URL using the given charset. |
Function | urlize |
Convert URLs in text into clickable links. |
Constant | F |
Undocumented |
Variable | concat |
Undocumented |
Variable | internal |
Undocumented |
Variable | missing |
Undocumented |
Class | _ |
Undocumented |
Variable | _email |
Undocumented |
Variable | _http |
Undocumented |
Jinja keeps internal caches for environments and lexers. These are used so that Jinja doesn't have to recreate environments and lexers all the time. Normally you don't have to care about that but if you are measuring memory consumption you may want to clean the caches.
Consumes an iterable without doing anything with it.
Parameters | |
iterable:t.Iterable[ | Undocumented |
Serialize an object to a string of JSON with :func:`json.dumps`, then replace HTML-unsafe characters with Unicode escapes and mark the result safe with :class:`~markupsafe.Markup`. This is available in templates as the ``|tojson`` filter. The following characters are escaped: ``<``, ``>``, ``&``, ``'``. The returned string is safe to render in HTML documents and ``<script>`` tags. The exception is in HTML attributes that are double quoted; either use single quotes or the ``|forceescape`` filter. :param obj: The object to serialize to JSON. :param dumps: The ``dumps`` function to use. Defaults to ``env.policies["json.dumps_function"]``, which defaults to :func:`json.dumps`. :param kwargs: Extra arguments to pass to ``dumps``. Merged onto ``env.policies["json.dumps_kwargs"]``. .. versionchanged:: 3.0 The ``dumper`` parameter is renamed to ``dumps``. .. versionadded:: 2.9
Parameters | |
obj:t.Any | Undocumented |
dumps:t.Optional[ | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
markupsafe.Markup | Undocumented |
Imports an object based on a string. This is useful if you want to use import paths as endpoints or something similar. An import path can be specified either in dotted notation (``xml.sax.saxutils.escape``) or with a colon as object delimiter (``xml.sax.saxutils:escape``). If the `silent` is True the return value will be `None` if the import fails. :return: imported object
Parameters | |
importstr | Undocumented |
silent:bool | Undocumented |
Returns | |
t.Any | Undocumented |
Check if the object passed is undefined. This does nothing more than performing an instance check against :class:`Undefined` but looks nicer. This can be used for custom filters or tests that want to react to undefined variables. For example a custom default filter can look like this:: def default(var, default=''): if is_undefined(var): return default return var
Parameters | |
obj:t.Any | Undocumented |
Returns | |
bool | Undocumented |
Returns a file descriptor for the filename if that file exists, otherwise ``None``.
Parameters | |
filename:str | Undocumented |
mode:str | Undocumented |
Returns | |
t.Optional[ | Undocumented |
Pass the :class:`~jinja2.runtime.Context` as the first argument to the decorated function when called while rendering a template. Can be used on functions, filters, and tests. If only ``Context.eval_context`` is needed, use :func:`pass_eval_context`. If only ``Context.environment`` is needed, use :func:`pass_environment`. .. versionadded:: 3.0.0 Replaces ``contextfunction`` and ``contextfilter``.
Parameters | |
f:F | Undocumented |
Returns | |
F | Undocumented |
Pass the :class:`~jinja2.Environment` as the first argument to the decorated function when called while rendering a template. Can be used on functions, filters, and tests. .. versionadded:: 3.0.0 Replaces ``environmentfunction`` and ``environmentfilter``.
Parameters | |
f:F | Undocumented |
Returns | |
F | Undocumented |
Pass the :class:`~jinja2.nodes.EvalContext` as the first argument to the decorated function when called while rendering a template. See :ref:`eval-context`. Can be used on functions, filters, and tests. If only ``EvalContext.environment`` is needed, use :func:`pass_environment`. .. versionadded:: 3.0.0 Replaces ``evalcontextfunction`` and ``evalcontextfilter``.
Parameters | |
f:F | Undocumented |
Returns | |
F | Undocumented |
Intelligently sets the initial value of autoescaping based on the filename of the template. This is the recommended way to configure autoescaping if you do not want to write a custom function yourself. If you want to enable it for all templates created from strings or for all templates with `.html` and `.xml` extensions:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( enabled_extensions=('html', 'xml'), default_for_string=True, )) Example configuration to turn it on at all times except if the template ends with `.txt`:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( disabled_extensions=('txt',), default_for_string=True, default=True, )) The `enabled_extensions` is an iterable of all the extensions that autoescaping should be enabled for. Likewise `disabled_extensions` is a list of all templates it should be disabled for. If a template is loaded from a string then the default from `default_for_string` is used. If nothing matches then the initial value of autoescaping is set to the value of `default`. For security reasons this function operates case insensitive. .. versionadded:: 2.9
Parameters | |
enabledt.Collection[ | Undocumented |
disabledt.Collection[ | Undocumented |
defaultbool | Undocumented |
default:bool | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Quote a string for use in a URL using the given charset. :param obj: String or bytes to quote. Other types are converted to string then encoded to bytes using the given charset. :param charset: Encode text to bytes using this charset. :param for_qs: Quote "/" and use "+" for spaces.
Parameters | |
obj:t.Any | Undocumented |
charset:str | Undocumented |
forbool | Undocumented |
Returns | |
str | Undocumented |
Convert URLs in text into clickable links. This may not recognize links in some situations. Usually, a more comprehensive formatter, such as a Markdown library, is a better choice. Works on ``http://``, ``https://``, ``www.``, ``mailto:``, and email addresses. Links with trailing punctuation (periods, commas, closing parentheses) and leading punctuation (opening parentheses) are recognized excluding the punctuation. Email addresses that include header fields are not recognized (for example, ``mailto:address@example.com?cc=copy@example.com``). :param text: Original text containing URLs to link. :param trim_url_limit: Shorten displayed URL values to this length. :param target: Add the ``target`` attribute to links. :param rel: Add the ``rel`` attribute to links. :param extra_schemes: Recognize URLs that start with these schemes in addition to the default behavior. .. versionchanged:: 3.0 The ``extra_schemes`` parameter was added. .. versionchanged:: 3.0 Generate ``https://`` links for URLs without a scheme. .. versionchanged:: 3.0 The parsing rules were updated. Recognize email addresses with or without the ``mailto:`` scheme. Validate IP addresses. Ignore parentheses and brackets in more cases.
Parameters | |
text:str | Undocumented |
trimt.Optional[ | Undocumented |
rel:t.Optional[ | Undocumented |
target:t.Optional[ | Undocumented |
extrat.Optional[ | Undocumented |
Returns | |
str | Undocumented |