Skip to content

Commit

Permalink
Merge pull request #1538 from pallets/docs-template
Browse files Browse the repository at this point in the history
rewrite Template class doc
  • Loading branch information
davidism committed Nov 9, 2021
2 parents e01e0a2 + 3f1e3fc commit 49987a3
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions src/jinja2/environment.py
Expand Up @@ -1115,33 +1115,20 @@ def make_globals(


class Template:
"""The central template object. This class represents a compiled template
and is used to evaluate it.
Normally the template object is generated from an :class:`Environment` but
it also has a constructor that makes it possible to create a template
instance directly using the constructor. It takes the same arguments as
the environment constructor but it's not possible to specify a loader.
Every template object has a few methods and members that are guaranteed
to exist. However it's important that a template object should be
considered immutable. Modifications on the object are not supported.
Template objects created from the constructor rather than an environment
do have an `environment` attribute that points to a temporary environment
that is probably shared with other templates created with the constructor
and compatible settings.
>>> template = Template('Hello {{ name }}!')
>>> template.render(name='John Doe') == u'Hello John Doe!'
True
>>> stream = template.stream(name='John Doe')
>>> next(stream) == u'Hello John Doe!'
True
>>> next(stream)
Traceback (most recent call last):
...
StopIteration
"""A compiled template that can be rendered.
Use the methods on :class:`Environment` to create or load templates.
The environment is used to configure how templates are compiled and
behave.
It is also possible to create a template object directly. This is
not usually recommended. The constructor takes most of the same
arguments as :class:`Environment`. All templates created with the
same environment arguments share the same ephemeral ``Environment``
instance behind the scenes.
A template object should be considered immutable. Modifications on
the object are not supported.
"""

#: Type of environment to create when creating a template directly
Expand Down

0 comments on commit 49987a3

Please sign in to comment.