@@ -9,30 +9,28 @@ This example is printing a basic HTML page with with a dynamic paragraph.
9
9
:lines: 5-
10
10
:linenos:
11
11
12
- Reusing templates
13
- -----------------
12
+ Caching/ Reusing templates
13
+ -------------------------
14
14
15
- The are two main ways of rendering templates:
15
+ The are two ways of rendering templates:
16
16
17
+ - manually creating a ``Template `` or ``FileTemplate `` object and calling its method
17
18
- using one of ``render_... `` methods
18
- - manually creating a ``Template `` object and calling its method
19
19
20
- While the first method is simpler, it also compiles the template on every call.
21
- The second method is more efficient when rendering the same template multiple times, as it allows
22
- to reuse the compiled template, at the cost of more memory usage.
23
20
24
- Both methods can be used interchangeably, as they both return the same result .
25
- It is up to the user to decide which method is more suitable for a given use case .
21
+ By dafault, the `` render_... `` methods cache the template and reuse it on next calls .
22
+ This speeds up the rendering process, but also uses more memory .
26
23
27
- **Generally, the first method will be sufficient for most use cases. **
24
+ If for some reason the caching is not desired, you can disable it by passing ``cache=False `` to
25
+ the ``render_... `` method. This will cause the template to be recreated on every call, which is slower,
26
+ but uses less memory. This might be useful when rendering a large number of different templates that
27
+ might not fit in the memory at the same time or are not used often enough to justify caching them.
28
28
29
- It is also worth noting that compiling all used templates using the second method might not be possible,
30
- depending on the project and board used, due to the limited amount of RAM.
31
29
32
30
.. literalinclude :: ../examples/templateengine_reusing.py
33
31
:caption: examples/templateengine_reusing.py
34
32
:lines: 5-
35
- :emphasize-lines: 1,16,20
33
+ :emphasize-lines: 22,27,34
36
34
:linenos:
37
35
38
36
Expressions
@@ -234,29 +232,20 @@ Autoescaping unsafe characters
234
232
------------------------------
235
233
236
234
Token ``{% autoescape off %} ... {% endautoescape %} `` is used for marking a block of code that should
237
- be not be autoescaped. Consequently using ``{% autoescape off %} ... `` does the opposite and turns
235
+ be not be autoescaped. Consequently using ``{% autoescape on %} ... `` does the opposite and turns
238
236
the autoescaping back on.
239
237
240
238
By default the template engine will escape all HTML-unsafe characters in expressions
241
239
(e.g. ``< `` will be replaced with ``< ``).
242
240
243
241
Content outside expressions is not escaped and is rendered as-is.
244
242
245
- For escaping XML and Markdown, you can use the ``language= `` parameter, both in ``render_... `` methods
246
- and in all ``Template `` constructors.
247
-
248
243
.. literalinclude :: ../examples/autoescape.html
249
244
:caption: examples/autoescape.html
250
245
:lines: 7-
251
246
:language: html
252
247
:linenos:
253
248
254
- .. literalinclude :: ../examples/autoescape.md
255
- :caption: examples/autoescape.md
256
- :lines: 5-
257
- :language: markdown
258
- :linenos:
259
-
260
249
.. literalinclude :: ../examples/templateengine_autoescape.py
261
250
:caption: examples/templateengine_autoescape.py
262
251
:lines: 5-
0 commit comments