diff options
author | David Lord <davidism@gmail.com> | 2021-11-09 10:05:35 -0800 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2021-11-09 10:05:35 -0800 |
commit | 3f1e3fccc24729ee0f2231a1e90d35ea4bff4e0d (patch) | |
tree | 4d9146c23cb30ea2723b8bf5303476a4f44cd848 /src | |
parent | e01e0a21f9157c5b09ea4131d94393fe347a2c82 (diff) | |
download | jinja2-3f1e3fccc24729ee0f2231a1e90d35ea4bff4e0d.tar.gz |
rewrite Template class doc
Diffstat (limited to 'src')
-rw-r--r-- | src/jinja2/environment.py | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/src/jinja2/environment.py b/src/jinja2/environment.py index 8a831db..a231d9c 100644 --- a/src/jinja2/environment.py +++ b/src/jinja2/environment.py @@ -1115,33 +1115,20 @@ class Environment: 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 |