Chapter 2. Templating with Jinja2
This chapter will cover the basics of Jinja2 templating from the perspective of Flask; we will also learn how to make applications with modular and extensible templates.
In this chapter, we will cover the following recipes:
- Bootstrap layout
- Block composition and layout inheritance
- Creating a custom context processor
- Creating a custom Jinja2 filter
- Creating a custom macro for forms
- Advanced date and time formatting
Introduction
In Flask, we can write a complete web application without the need of any third-party templating engine. For example, have a look at the following code; this is a simple Hello World application with a bit of HTML styling included:
from flask import Flask app = Flask(__name__) @app.route('/') @app.route('/hello') ...
Get Flask Framework Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.