Undocumented
Constant | F |
Undocumented |
Variable | concat |
Undocumented |
Variable | internal_code |
Undocumented |
Variable | missing |
Undocumented |
Class | _PassArg |
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 | Markup |
Undocumented |
Class | Namespace |
A namespace object that can hold arbitrary attributes. It may be initialized from a dictionary or with keyword arguments. |
Function | clear_caches |
No summary |
Function | consume |
Consumes an iterable without doing anything with it. |
Function | contextfunction |
Pass the context as the first argument to the decorated function. |
Function | environmentfunction |
Pass the environment as the first argument to the decorated function. |
Function | escape |
Undocumented |
Function | evalcontextfunction |
Pass the eval context as the first argument to the decorated function. |
Function | generate_lorem_ipsum |
Generate some lorem ipsum for the template. |
Function | htmlsafe_json_dumps |
Serialize an object to a string of JSON with json.dumps , then replace HTML-unsafe characters with Unicode escapes and mark the result safe with ~markupsafe.Markup . |
Function | import_string |
No summary |
Function | internalcode |
Marks the function as internally used |
Function | is_undefined |
No summary |
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 ~jinja2.runtime.Context as the first argument to the decorated function when called while rendering a template. |
Function | pass_environment |
Pass the ~jinja2.Environment as the first argument to the decorated function when called while rendering a template. |
Function | pass_eval_context |
Pass the ~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 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 | unicode_urlencode |
Undocumented |
Function | url_quote |
Quote a string for use in a URL using the given charset. |
Function | urlize |
Convert URLs in text into clickable links. |
Variable | _email_re |
Undocumented |
Variable | _http_re |
Undocumented |
Parameters | |
iterable:t.Iterable[ | Undocumented |
Parameters | |
n:int | Undocumented |
html:bool | Undocumented |
min:int | Undocumented |
max:int | Undocumented |
Returns | |
str | Undocumented |
Serialize an object to a string of JSON with json.dumps
,
then replace HTML-unsafe characters with Unicode escapes and mark
the result safe with ~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.
Parameters | |
obj:t.Any | The object to serialize to JSON. |
dumps:t.Optional[ | The dumps function to use. Defaults to
env.policies["json.dumps_function"], which defaults to
json.dumps . |
**kwargs:t.Any | Extra arguments to pass to dumps. Merged onto env.policies["json.dumps_kwargs"]. |
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.
Parameters | |
import_name:str | Undocumented |
silent:bool | Undocumented |
Returns | |
t.Any | imported object |
Check if the object passed is undefined. This does nothing more than
performing an instance check against 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 |
None
and Ellipsis
).Parameters | |
obj:t.Any | Undocumented |
Returns | |
str | Undocumented |
Parameters | |
filename:str | Undocumented |
mode:str | Undocumented |
Returns | |
t.Optional[ | Undocumented |
Pass the ~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
pass_eval_context
. If only Context.environment is
needed, use pass_environment
.
Parameters | |
f:F | Undocumented |
Returns | |
F | Undocumented |
Pass the ~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
pass_environment
.
Parameters | |
f:F | Undocumented |
Returns | |
F | Undocumented |
pprint.pformat
.Parameters | |
obj:t.Any | Undocumented |
Returns | |
str | 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.
Parameters | |
enabled_extensions:t.Collection[ | Undocumented |
disabled_extensions:t.Collection[ | Undocumented |
default_for_string:bool | Undocumented |
default:bool | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Undocumented
Parameters | |
obj:t.Any | Undocumented |
charset:str | Undocumented |
for_qs:bool | Undocumented |
Returns | |
str | Undocumented |
Parameters | |
obj:t.Any | String or bytes to quote. Other types are converted to string then encoded to bytes using the given charset. |
charset:str | Encode text to bytes using this charset. |
for_qs:bool | Quote "/" and use "+" for spaces. |
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).
Parameters | |
text:str | Original text containing URLs to link. |
trim_url_limit:t.Optional[ | Shorten displayed URL values to this length. |
rel:t.Optional[ | Add the rel attribute to links. |
target:t.Optional[ | Add the target attribute to links. |
extra_schemes:t.Optional[ | Recognize URLs that start with these schemes in addition to the default behavior. |
Returns | |
str | Undocumented |