@@ -9,30 +9,28 @@ This example is printing a basic HTML page with with a dynamic paragraph.
99 :lines: 5-
1010 :linenos:
1111
12- Reusing templates
13- -----------------
12+ Caching/ Reusing templates
13+ -------------------------
1414
15- The are two main ways of rendering templates:
15+ The are two ways of rendering templates:
1616
17+ - manually creating a ``Template `` or ``FileTemplate `` object and calling its method
1718- using one of ``render_... `` methods
18- - manually creating a ``Template `` object and calling its method
1919
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.
2320
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 .
2623
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.
2828
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.
3129
3230.. literalinclude :: ../examples/templateengine_reusing.py
3331 :caption: examples/templateengine_reusing.py
3432 :lines: 5-
35- :emphasize-lines: 1,16,20
33+ :emphasize-lines: 22,27,34
3634 :linenos:
3735
3836Expressions
@@ -234,29 +232,20 @@ Autoescaping unsafe characters
234232------------------------------
235233
236234Token ``{% 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
238236the autoescaping back on.
239237
240238By default the template engine will escape all HTML-unsafe characters in expressions
241239(e.g. ``< `` will be replaced with ``< ``).
242240
243241Content outside expressions is not escaped and is rendered as-is.
244242
245- For escaping XML and Markdown, you can use the ``language= `` parameter, both in ``render_... `` methods
246- and in all ``Template `` constructors.
247-
248243.. literalinclude :: ../examples/autoescape.html
249244 :caption: examples/autoescape.html
250245 :lines: 7-
251246 :language: html
252247 :linenos:
253248
254- .. literalinclude :: ../examples/autoescape.md
255- :caption: examples/autoescape.md
256- :lines: 5-
257- :language: markdown
258- :linenos:
259-
260249.. literalinclude :: ../examples/templateengine_autoescape.py
261250 :caption: examples/templateengine_autoescape.py
262251 :lines: 5-
0 commit comments