Skip to content
Myr

Merge pull request #1538 from pallets/docs-template

Before adoption: this commit came in with the history the project adopted, so no landing records it.

rewrite Template class doc

authored by David Lord · committed by GitHub · parents e01e0a2, 3f1e3fc · Browse files · 1 file+11 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+11 added−24 removed

  • other:+11 added−24 removed

1 file+11 added−24 removed

modified:src/jinja2/environment.py+11 added-24 removed
1113 unmodified lines
1114 return ChainMap(d, self.globals)111511161117class Template:1118 """The central template object. This class represents a compiled template1119 and is used to evaluate it.1118 """A compiled template that can be rendered.11191121 Normally the template object is generated from an :class:`Environment` but1122 it also has a constructor that makes it possible to create a template1123 instance directly using the constructor. It takes the same arguments as1124 the environment constructor but it's not possible to specify a loader.1120 Use the methods on :class:`Environment` to create or load templates.1121 The environment is used to configure how templates are compiled and1122 behave.11231126 Every template object has a few methods and members that are guaranteed1127 to exist. However it's important that a template object should be1128 considered immutable. Modifications on the object are not supported.1124 It is also possible to create a template object directly. This is1125 not usually recommended. The constructor takes most of the same1126 arguments as :class:`Environment`. All templates created with the1127 same environment arguments share the same ephemeral ``Environment``1128 instance behind the scenes.11291130 Template objects created from the constructor rather than an environment1131 do have an `environment` attribute that points to a temporary environment1132 that is probably shared with other templates created with the constructor1133 and compatible settings.11341135 >>> template = Template('Hello {{ name }}!')1136 >>> template.render(name='John Doe') == u'Hello John Doe!'1137 True1138 >>> stream = template.stream(name='John Doe')1139 >>> next(stream) == u'Hello John Doe!'1140 True1141 >>> next(stream)1142 Traceback (most recent call last):1143 ...1144 StopIteration1130 A template object should be considered immutable. Modifications on1131 the object are not supported.1132 """11331134 #: Type of environment to create when creating a template directly1135 #: rather than through an existing environment.
526 unmodified lines