Jinja Escaping

Handling Special Characters with Escaping n nnJinja’s syntax is built around special characters like {{, {%, and # that define variables, tags, and comments. However, there are times when you need to display these exact characters as literal text in your rendered output, not as Jinja’s command syntax. This is where Jinja’s escaping mechanisms become…

Jinja Other Operators: () parentheses

Jinja Operator: () (Parentheses) n nnThe () operator in Jinja2 is used to call a callable object, such as a function, a method, or a macro. Just like in Python, you place the parentheses after the name of the callable to execute it. You can pass arguments inside the parentheses to customize the function’s behavior,…

Jinja Math Expression: % modulo

Jinja2 Arithmetic Expression: % (Modulo) n nnThe % operator in Jinja2 is an arithmetic operator that calculates the remainder of an integer division. It is also known as the modulo operator. This is a fundamental tool for various tasks in templating, such as determining if a number is even or odd, creating a checkerboard pattern,…

Jinja Template Inheritance

Jinja Template Inheritance n n Template inheritance allows you to create a reusable base layout that child templates can extend and override specific content blocks within. nn n n Example: base.html and child.html n base.html (the skeleton) n <!DOCTYPE html>n<html lang=”en”>n<head>n <title>{% block title %}{% endblock %} – My Site</title>n</head>n<body>n <div id=”header”>n <h1>My Website</h1>n </div>n…

Jinja Template Inheritance: base template

Jinja Base Template n n The base template is the foundation of Jinja’s template inheritance system. It serves as a skeleton for your website, defining the common layout and boilerplate code that is shared across multiple pages. This includes elements like the DOCTYPE, the “, “, and “ tags, and shared components such as a…

Jinja’s i18n Extension Introduction

An Introduction to Jinja’s i18n Extension n nnIf you’re building a web application with a global audience, one of your key considerations will be internationalization (i18n)—the process of adapting your app to different languages and regions. Doing this well requires a strategy that separates your content from your code. Jinja, as a templating engine, is…