Skip to content

Commit 9aac43b

Browse files
committed
new jinja2 page
1 parent 9e0e0e9 commit 9aac43b

File tree

74 files changed

+464
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+464
-21
lines changed

about-author.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ <h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Ta
124124
<a href="/template-engines.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Template Engines</a>
125125
<a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Web Application Security</a>
126126
<a href="/static-site-generator.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Static Site Generators</a>
127+
<a href="/jinja2.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Jinja2</a>
127128
<a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Data</a>
128129
<a href="/databases.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Databases</a>
129130
<a href="/no-sql-datastore.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>NoSQL Data Stores</a>

all.html

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,8 +3054,8 @@ <h2>Why are template engines important?</h2>
30543054
with the exception of the <code>&lt;meta name="description"...</code> line which provides
30553055
a unique short description of what the individual page contains.</p>
30563056
<p>The <a href="https://github.com/makaimc/fullstackpython.com/blob/gh-pages/source/theme/templates/base.html">base.html Jinja template</a> used to generate Full Stack Python
3057-
allows every page on Full Stack Python to have consistent HTML but
3058-
dynamically generate the pieces that should change between pages when
3057+
allows every page on the site to have consistent HTML but
3058+
dynamically generate the pieces that need to change between pages when
30593059
the <a href="/static-site-generator.html">static site generator</a> executes. The below
30603060
code from the <code>base.html</code> template shows that the meta description is up to child
30613061
templates to create.</p>
@@ -3076,18 +3076,22 @@ <h2>Why are template engines important?</h2>
30763076
generate the HTML output response when an HTTP request comes in for a
30773077
particular URL. </p>
30783078
<h2>Python template engines</h2>
3079-
<p>There are several popular Python template engines. Template engines have to
3080-
walk the spectrum between allowing arbitrary code execution and granting only
3081-
a limited set of capabilities via template tags.</p>
3079+
<p>There are several popular Python template engines. A template engine implementation
3080+
will fall somewhere on the spectrum between allowing arbitrary code execution and
3081+
granting only a limited set of capabilities via template tags. A rough visual of
3082+
the code in template spectrum can be seen below for four of the major Python
3083+
template engines.</p>
3084+
<p><img src="theme/img/template-logic-spectrum.png" width="100%" alt="." class="technical-diagram" style="border-radius: 5px;"></p>
30823085
<h3>Jinja</h3>
3083-
<p><a href="http://jinja.pocoo.org/">Jinja</a>, also known as "Jinja2" is a popular Python
3086+
<p><a href="http://jinja.pocoo.org/">Jinja</a>, also known as "Jinja2", is a popular Python
30843087
template engine written as an independent open source project, unlike some
30853088
template engines that are provided as part of a larger web framework.</p>
30863089
<p>Major Python open source applications such as the
30873090
<a href="/configuration-management.html">configuration management</a> tools Ansible
30883091
and <a href="https://github.com/saltstack/salt">SaltStack</a>
30893092
as well as the <a href="/static-site-generator.html">static site generator</a> Pelican use
30903093
the Jinja template engine by default for generating output files.</p>
3094+
<p>There's a whole lot more to learn about Jinja on the <a href="/jinja2.html">Jinja2</a> page.</p>
30913095
<h3>Django templating</h3>
30923096
<p>Django comes with its
30933097
<a href="https://docs.djangoproject.com/en/dev/topics/templates/">own template engine</a>
@@ -3485,6 +3489,57 @@ <h3>Static site generator resources</h3>
34853489
is a tutorial I wrote to use the Full Stack Python source code to create
34863490
and deploy your first static site.</p>
34873491
</li>
3492+
</ul>
3493+
<h1>Jinja2</h1>
3494+
<p>Jinja2 is a Python <a href="/template-engines.html">template engine</a> used to create
3495+
HTML, XML or other markup formats that are returned to the user via an
3496+
HTTP response.</p>
3497+
<h2>Why is Jinja2 useful?</h2>
3498+
<p>Jinja2 didn't invent the templating concept. In fact, Jinja2's syntax is
3499+
inspired by Django's built-in template engine, which was released years
3500+
earlier. There were many template engines, such as <a href="https://en.wikipedia.org/wiki/JavaServer_Pages">JavaServer Pages (JSPs)</a> </p>
3501+
<p>Jinja2 is most useful because it has consistent template tag syntax and the
3502+
project is cleanly extracted as
3503+
<a href="https://github.com/mitsuhiko/jinja2">an independent open source project</a> so
3504+
it can be used a dependency by other code libraries.</p>
3505+
<p>Jinja2 strikes a thoughtful balance on the template engine spectrum where
3506+
on one end you can embed arbitrary code in the templates and the other
3507+
end a developer can code whatever she wants.</p>
3508+
<h2>What projects depend on Jinja2?</h2>
3509+
<p>Jinja2 is a commonly-used templating engine for
3510+
<a href="/web-frameworks.html">web frameworks</a> such as <a href="/flask.html">Flask</a>,
3511+
<a href="/bottle.html">Bottle</a> <a href="/morepath.html">Morepath</a> and, as of its 1.8 update,
3512+
optionally <a href="/django.html">Django</a> as well. Jinja2 is also used as a template
3513+
language by <a href="/configuration-management.html">configuration management</a> tool
3514+
Ansible and the <a href="/static-site-generators.html">static site generator</a> Pelican,
3515+
among many other similar tools.</p>
3516+
<p>The idea is that if a developer already knows Jinja2 from working with one
3517+
project then the exact same syntax and style can be used in another project
3518+
that requires templating. The re-use reduces the learning curve and saves the
3519+
open source project author from having to reinvent a new templating style.</p>
3520+
<h3>Jinja2 resources</h3>
3521+
<ul>
3522+
<li>
3523+
<p>Real Python has a nice
3524+
<a href="https://realpython.com/blog/python/primer-on-jinja-templating/">Jinja2 primer</a>
3525+
with many code examples to show how to use the template engine.</p>
3526+
</li>
3527+
<li>
3528+
<p>The <a href="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-ii-templates">second part of the Flask mega tutorial</a>
3529+
is all about Jinja2 templates. It walks through control flow, template inheritance
3530+
and other standard features of the engine.</p>
3531+
</li>
3532+
<li>
3533+
<p><a href="http://jonathanchu.is/posts/upgrading-jinja2-templates-django-18-with-admin/">Upgrading to Jinja2 Templates in Django 1.8 With Admin</a>
3534+
shows how to fix an issue that can occur with Django 1.8 and using Jinja2 as
3535+
the template engine.</p>
3536+
</li>
3537+
<li>
3538+
<p>The official
3539+
<a href="http://jinja.pocoo.org/docs/dev/templates/">Jinja2 template designer documentation</a>
3540+
is exceptionally useful both as a reference as well as a full read-through
3541+
to understand how to properly work with template tags.</p>
3542+
</li>
34883543
</ul>
34893544
<h1>Data</h1>
34903545
<p>Data is an incredibly broad topic but it can be broken down into many

api-creation.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ <h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Ta
365365
<a href="/template-engines.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Template Engines</a>
366366
<a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Web Application Security</a>
367367
<a href="/static-site-generator.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Static Site Generators</a>
368+
<a href="/jinja2.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Jinja2</a>
368369
<a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Data</a>
369370
<a href="/databases.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Databases</a>
370371
<a href="/no-sql-datastore.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>NoSQL Data Stores</a>

api-integration.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ <h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Ta
220220
<a href="/template-engines.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Template Engines</a>
221221
<a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Web Application Security</a>
222222
<a href="/static-site-generator.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Static Site Generators</a>
223+
<a href="/jinja2.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Jinja2</a>
223224
<a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Data</a>
224225
<a href="/databases.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Databases</a>
225226
<a href="/no-sql-datastore.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>NoSQL Data Stores</a>

application-dependencies.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ <h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Ta
284284
<a href="/template-engines.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Template Engines</a>
285285
<a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Web Application Security</a>
286286
<a href="/static-site-generator.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Static Site Generators</a>
287+
<a href="/jinja2.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Jinja2</a>
287288
<a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Data</a>
288289
<a href="/databases.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Databases</a>
289290
<a href="/no-sql-datastore.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>NoSQL Data Stores</a>

application-programming-interfaces.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ <h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Ta
197197
<a href="/template-engines.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Template Engines</a>
198198
<a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Web Application Security</a>
199199
<a href="/static-site-generator.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Static Site Generators</a>
200+
<a href="/jinja2.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Jinja2</a>
200201
<a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Data</a>
201202
<a href="/databases.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Databases</a>
202203
<a href="/no-sql-datastore.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>NoSQL Data Stores</a>

best-python-resources.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ <h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Ta
318318
<a href="/template-engines.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Template Engines</a>
319319
<a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Web Application Security</a>
320320
<a href="/static-site-generator.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Static Site Generators</a>
321+
<a href="/jinja2.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Jinja2</a>
321322
<a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Data</a>
322323
<a href="/databases.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Databases</a>
323324
<a href="/no-sql-datastore.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>NoSQL Data Stores</a>

best-python-videos.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ <h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Ta
249249
<a href="/template-engines.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Template Engines</a>
250250
<a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Web Application Security</a>
251251
<a href="/static-site-generator.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Static Site Generators</a>
252+
<a href="/jinja2.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Jinja2</a>
252253
<a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Data</a>
253254
<a href="/databases.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Databases</a>
254255
<a href="/no-sql-datastore.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>NoSQL Data Stores</a>

bottle.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ <h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Ta
185185
<a href="/template-engines.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Template Engines</a>
186186
<a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Web Application Security</a>
187187
<a href="/static-site-generator.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Static Site Generators</a>
188+
<a href="/jinja2.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Jinja2</a>
188189
<a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Data</a>
189190
<a href="/databases.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Databases</a>
190191
<a href="/no-sql-datastore.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>NoSQL Data Stores</a>

caching.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ <h3 class="panel-head"><a href="/table-of-contents.html" style="color: #fff;">Ta
164164
<a href="/template-engines.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Template Engines</a>
165165
<a href="/web-application-security.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Web Application Security</a>
166166
<a href="/static-site-generator.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Static Site Generators</a>
167+
<a href="/jinja2.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Jinja2</a>
167168
<a href="/data.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Data</a>
168169
<a href="/databases.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>Databases</a>
169170
<a href="/no-sql-datastore.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>NoSQL Data Stores</a>

0 commit comments

Comments
 (0)