Skip to Content
Mastering Flask Web Development - Second Edition
book

Mastering Flask Web Development - Second Edition

by Daniel Gaspar, Jack Stouffer
October 2018
Intermediate to advanced
332 pages
8h 9m
English
Packt Publishing
Content preview from Mastering Flask Web Development - Second Edition

The child templates

Now that we have outlined the base layout, we need to implement all the child pages that will extend the base. Take a look at the way we are implementing the home page and inherit/override the left body block, as shown in the following code:

{% extends "base.html" %}{% import 'macros.html' as macros %}{% block title %}Home{% endblock %}{% block leftbody %}{{ macros.render_posts(posts) }}{{ macros.render_pagination(posts, 'home') }}{% endblock %}

Surprisingly simple, this template extends the base template has expected, and then overrides the title and leftbody block sections. Inside, the leftbody uses two macros to render the posts and their pagination. The macros help us to reuse Jinja2 code and use it like functions, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg
Flask Web Development

Flask Web Development

Miguel Grinberg

Publisher Resources

ISBN: 9781788995405Supplemental Content