module documentation

Undocumented

Class Cycler Cycle through values by yield them one at a time, then restarting once the end is reached. Available as ``cycler`` in templates.
Class Joiner A joining helper for templates.
Class LRUCache A simple LRU Cache implementation.
Class Namespace A namespace object that can hold arbitrary attributes. It may be initialized from a dictionary or with keyword arguments.
Function clear_caches 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_lorem_ipsum Generate some lorem ipsum for the template.
Function htmlsafe_json_dumps 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_string 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_undefined 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_type_repr 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_if_exists Returns a file descriptor for the filename if that file exists, otherwise ``None``.
Function pass_context Pass the :class:`~jinja2.runtime.Context` as the first argument to the decorated function when called while rendering a template.
Function pass_environment Pass the :class:`~jinja2.Environment` as the first argument to the decorated function when called while rendering a template.
Function pass_eval_context 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_autoescape 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 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_code Undocumented
Variable missing Undocumented
Class _PassArg Undocumented
Variable _email_re Undocumented
Variable _http_re Undocumented
def clear_caches(): (source)

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.

def consume(iterable): (source)

Consumes an iterable without doing anything with it.

Parameters
iterable:t.Iterable[t.Any]Undocumented
def generate_lorem_ipsum(n=5, html=True, min=20, max=100): (source)

Generate some lorem ipsum for the template.

Parameters
n:intUndocumented
html:boolUndocumented
min:intUndocumented
max:intUndocumented
Returns
strUndocumented
def htmlsafe_json_dumps(obj, dumps=None, **kwargs): (source)

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.AnyUndocumented
dumps:t.Optional[t.Callable[..., str]]Undocumented
**kwargs:t.AnyUndocumented
Returns
markupsafe.MarkupUndocumented
def import_string(import_name, silent=False): (source)

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
import_name:strUndocumented
silent:boolUndocumented
Returns
t.AnyUndocumented
def internalcode(f): (source)

Marks the function as internally used

Parameters
f:FUndocumented
Returns
FUndocumented
def is_undefined(obj): (source)

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.AnyUndocumented
Returns
boolUndocumented
def object_type_repr(obj): (source)

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`).

Parameters
obj:t.AnyUndocumented
Returns
strUndocumented
def open_if_exists(filename, mode='rb'): (source)

Returns a file descriptor for the filename if that file exists, otherwise ``None``.

Parameters
filename:strUndocumented
mode:strUndocumented
Returns
t.Optional[t.IO]Undocumented
def pass_context(f): (source)

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:FUndocumented
Returns
FUndocumented
def pass_environment(f): (source)

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:FUndocumented
Returns
FUndocumented
def pass_eval_context(f): (source)

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:FUndocumented
Returns
FUndocumented
def pformat(obj): (source)

Format an object using :func:`pprint.pformat`.

Parameters
obj:t.AnyUndocumented
Returns
strUndocumented
def select_autoescape(enabled_extensions=('html', 'htm', 'xml'), disabled_extensions=(), default_for_string=True, default=False): (source)

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
enabled_extensions:t.Collection[str]Undocumented
disabled_extensions:t.Collection[str]Undocumented
default_for_string:boolUndocumented
default:boolUndocumented
Returns
t.Callable[[t.Optional[str]], bool]Undocumented
def url_quote(obj, charset='utf-8', for_qs=False): (source)

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.AnyUndocumented
charset:strUndocumented
for_qs:boolUndocumented
Returns
strUndocumented
def urlize(text, trim_url_limit=None, rel=None, target=None, extra_schemes=None): (source)

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:strUndocumented
trim_url_limit:t.Optional[int]Undocumented
rel:t.Optional[str]Undocumented
target:t.Optional[str]Undocumented
extra_schemes:t.Optional[t.Iterable[str]]Undocumented
Returns
strUndocumented

Undocumented

Value
t.TypeVar('F',
          bound=t.Callable[..., t.Any])
concat = (source)

Undocumented

internal_code: t.MutableSet[CodeType] = (source)

Undocumented

missing: t.Any = (source)

Undocumented

_email_re = (source)

Undocumented

_http_re = (source)

Undocumented