You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<span class="nt"><meta</span> <span class="na">name=</span><span class="s">"description"</span> <span class="na">content=</span><span class="s">"Template engines provide programmatic output of formatted content such as HTML, XML or PDF."</span><span class="nt">></span>
<span class="nt"><meta</span> <span class="na">name=</span><span class="s">"description"</span> <span class="na">content=</span><span class="s">"Template engines provide programmatic output of formatted content such as HTML, XML or PDF."</span><span class="nt">></span>
<p>Every one of the HTML lines above is standard for each page on Full Stack Python,
4042
-
with the exception of the <code><meta name="description"...</code> line which provides
4043
-
a unique short description of what the individual page contains.</p>
4044
-
<p>The <a href="https://github.com/mattmakai/fullstackpython.com/blob/gh-pages/source/theme/templates/base.html">base.html Jinja template</a> used to generate Full Stack Python
4045
-
allows every page on the site to have consistent HTML but
4046
-
dynamically generate the pieces that need to change between pages when
4047
-
the <a href="/static-site-generator.html">static site generator</a> executes. The below
4048
-
code from the <code>base.html</code> template shows that the meta description is up to child
4049
-
templates to create.</p>
4043
+
<p>Every one of the HTML lines above is standard for each page on Full Stack
4044
+
Python, with the exception of the <code><meta name="description"...</code> line which
4045
+
provides a unique short description of what the individual page contains.</p>
<p>In a typical <a href="/wsgi-servers.html">WSGI application</a>, the template engine would
4064
-
generate the HTML output response when an HTTP request comes in for a
4066
+
<p>In a typical <a href="/wsgi-servers.html">WSGI application</a>, the template engine
4067
+
would generate the HTML output response when an HTTP request comes in for a
4065
4068
particular URL. </p>
4066
4069
<h2>Python template engines</h2>
4067
-
<p>There are several popular Python template engines. A template engine implementation
4068
-
will fall somewhere on the spectrum between allowing arbitrary code execution and
4069
-
granting only a limited set of capabilities via template tags. A rough visual of
4070
-
the code in template spectrum can be seen below for four of the major Python
4071
-
template engines.</p>
4070
+
<p>There are several popular Python template engines. A template engine
4071
+
implementation will fall somewhere on the spectrum between allowing
4072
+
arbitrary code execution and granting only a limited set of capabilities
4073
+
via template tags. A rough visual of the code in template spectrum can be
4074
+
seen below for four of the major Python template engines.</p>
4072
4075
<p><img src="/img/template-logic-spectrum.png" width="100%" alt="Spectrum between no logic in templates and the ability to run arbitrary code." class="technical-diagram" style="border-radius: 5px;"></p>
4073
-
<h3>Jinja</h3>
4074
-
<p><a href="http://jinja.pocoo.org/">Jinja</a>, also known as "Jinja2", is a popular Python
4075
-
template engine written as an independent open source project, unlike some
4076
-
template engines that are provided as part of a larger web framework.</p>
4076
+
<h3>Jinja (Jinja2)</h3>
4077
+
<p><a href="/jinja2.html">Jinja</a>, also known and referred to as "Jinja2", is a popular
4078
+
Python template engine written as a self-contained open source project. Some
4079
+
template engines, such as <a href="/django-templates.html">Django templates</a> are
4080
+
provided as part of a larger <a href="/web-frameworks.html">web framework</a>, which
4081
+
can make them difficult to reuse in projects outside their coupled library.</p>
4077
4082
<p>Major Python open source applications such as the
is an older but still relevant post by the creator of
4150
+
<a href="/jinja2.html">Jinja</a> that explains why and how he switches between Mako,
4151
+
Jinja and Genshi for various projects he works on. </p>
4152
+
</li>
4153
+
<li>
4154
+
<p><a href="https://www.quora.com/Python-Web-Frameworks/Python-Web-Frameworks-What-are-the-advantages-and-disadvantages-of-using-Mako-vs-Jinja2">Python Web Frameworks: What are the advantages and disadvantages of using Mako vs. Jinja2?</a>
4155
+
has some good answers from developers on Quora about using Mako compared
4156
+
with Jinja2.</p>
4157
+
</li>
4158
+
</ul>
4092
4159
<h3>Template engine resources</h3>
4160
+
<p>Template engines are often used with web frameworks a black box where input
4161
+
goes in, and rendered text magically appears out the other side. However,
4162
+
when something unexpected returns from a template engine it is useful to
4163
+
know how they work to aid your debugging. The following resources examine
4164
+
existing template engine design as well as how to build your own engine
4165
+
when that's necessary for your projects.</p>
4093
4166
<ul>
4094
4167
<li>
4168
+
<p><a href="https://fengsp.github.io/blog/2016/8/how-a-template-engine-works/">How a template engine works</a>
4169
+
uses the template module in Tornado as an example to step through how
4170
+
a template engine produces output, from parsing the incoming string to
4171
+
rendering the final output.</p>
4172
+
</li>
4173
+
<li>
4095
4174
<p><a href="http://aosabook.org/en/500L/a-template-engine.html">A template engine in 500 lines or less</a>
4096
4175
is an article by <a href="http://nedbatchelder.com/">Ned Batchelder</a> provides a<br />
4097
4176
template engine in 252 lines of Python that can be used to understand how
4098
4177
template engines work under the cover.</p>
4099
4178
</li>
4100
4179
<li>
4101
-
<p><a href="https://realpython.com/blog/python/primer-on-jinja-templating/">A Primer on Jinja Templating</a>
4102
-
shows how to use the major parts of this fantastic template engine.</p>
4103
-
</li>
4104
-
<li>
4105
4180
<p><a href="http://agiliq.com/blog/2015/08/template-fragment-caching-gotchas/">Template fragment gotchas</a>
4106
4181
is a collection of situations that can trip up a developer or designer when
0 commit comments