48 captures
04 Jan 2016 - 30 Jan 2026
Sep OCT Nov
27
2020 2021 2022
success
fail

About this capture

COLLECTED BY

Collection: Save Page Now Outlinks

TIMESTAMPS

The Wayback Machine - http://web.archive.org/web/20211027140808/https://www.fullstackpython.com/jinja2.html
 

Full Stack Python logoFull Stack Python
All topics | Blog | Supporter's Edition | @fullstackpython | Facebook | What's new?

Jinja2






Jinja, also commonly referred to as "Jinja2" to specify the newest release version, is a Python template engine used to create HTML, XML or other markup formats that are returned to the user via an HTTP response.

Logo for the Jinja template engine project.

Why is Jinja2 useful?


Jinja2 is useful because it has consistent template tag syntax and the project is cleanly extracted as an independent open source project so it can be used as a dependency by other code libraries.

Jinja2 is an implementation of the template engines concept. Learn more in the web development chapter or view the table of contents for all topics.

Jinja2 strikes a thoughtful balance on the template engine spectrum where on one end you can embed arbitrary code in the templates and the other end a developer can code whatever she wants.

Jinja2 origin and development


The first recorded public released of Jinja2 was in 2008 with 2.0rc1. Since then the engine has seen numerous updates and remains under active development.

Jinja2 engine certainly wasn't the first template engine. In fact, Jinja2's syntax is inspired by Django's built-in template engine, which was released several years earlier. There were many template systems, such as JavaServer Pages (JSPs), that originated almost a decade before Jinja2. Jinja2 built upon the concepts of other template engines and today is widely used by the Python community.

What projects depend on Jinja2?


Jinja2 is a commonly-used templating engine for web frameworks such as Flask, Bottle, Morepath and, as of its 1.8 update, optionally Django as well. Jinja2 is also used as a template language by configuration management tool Ansible and the static site generator Pelican, among many other similar tools.

The idea is that if a developer already knows Jinja2 from working with one project then the exact same syntax and style can be used in another project that requires templating. The re-use reduces the learning curve and saves the open source project author from having to reinvent a new templating style.

Jinja2 resources




Real Python has a nice Jinja2 primer with many code examples to show how to use the template engine.



The second part of the Flask mega tutorial is all about Jinja2 templates. It walks through control flow, template inheritance and other standard features of the engine.



Upgrading to Jinja2 Templates in Django 1.8 With Admin shows how to fix an issue that can occur with Django 1.8 and using Jinja2 as the template engine.



The official Jinja2 templates documentation is exceptionally useful both as a reference as well as a full read-through to understand how to properly work with template tags.



When you want to use Jinja2 outside of a web framework or other existing tool, here's a handy quick load function snippet so the template engine can be easily used from a script or the REPL.



When working with Jinja2 in combination with LaTeX, some of Jinja2's blocks can conflict with LaTeX commands. Check out this post on LaTeX templates with Python and Jinja2 to generate PDFs to resolve those issues.



When you use Jinja2 for long enough, eventually you'll want to escape large blocks of Jinja2-like text in your templates. To do so, you'll need the "raw" template tag.



Python Templating Performance Showdown: Django vs Jinja puts together some benchmarks for how Django templates compare with Jinja templates. The usual benchmarking caveats apply here but there are some interesting tests that examine how the template engines handle large numbers of variables and other factors.



Universal Jinja presents a high-level overview of what you could do using the Jinja-like Nunchuks library to perform server-side template rendering for Django applications.


Learn more about template engines or move to a new topic?





What are template engines and why are they useful?
 




I want to learn how to code a Python web application using a framework.
 




I've built a Python web app, now how do I deploy it?
 





Sponsored By


AssemblyAI logo
The most accurate speech-to-text API. Built for Python developers.





Table of Contents



1. Introduction 2. Development Environments 3. Data 4. Web Development Web Frameworks Django Flask Bottle Pyramid TurboGears Falcon Morepath Sanic Other Web Frameworks Template Engines Jinja2 Mako Django Templates Web Design HTML Cascading Style Sheets (CSS) Responsive Design Minification CSS Frameworks Bootstrap Foundation JavaScript React Vue.js Angular Task Queues Celery Redis Queue (RQ) Dramatiq Static Site Generators Pelican Lektor MkDocs Testing Unit Testing Integration Testing Debugging Code Metrics Networking HTTPS WebSockets WebRTC Web APIs Microservices Webhooks Bots API Creation API Frameworks Django REST Framework API Integration Twilio Stripe Slack Okta Security SQL Injection CSRF 5. Deployment 6. DevOps Changelog What Full Stack Means About the Author Future Directions Page Statuses ...or view the full table of contents.



Full Stack Python


Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.

Updates via Twitter & Facebook.



Chapters



1. Introduction 2. Development Environments 3. Data 4. Web Development » Jinja2 5. Deployment 6. DevOps Changelog What Full Stack Means About the Author Future Directions Page Statuses ...or view the full table of contents.

 



Matt Makai 2012-2021