Chapter 11. Building Your Own Extension

From the first chapter of this book, we have been adding Flask extensions to our app in order to add new features and save us from spending lots of time to reinvent the wheel. Up to this point, it was unknown how these Flask extensions worked. In this chapter, we will create two simple Flask extensions in order to better understand Flask's internals and allow you to extend Flask with your own functionality.

Creating a YouTube Flask extension

To begin, the first extension we are going to create is a simple extension that allows embedding YouTube videos in Jinja templates with the following tag:

{{ youtube(video_id) }}

The video_id object is the code after the v in any YouTube URL. For example, in the URL https://www.youtube.com/watch?v=_OBlgSz8sSM ...

Get Flask: Building Python Web Services now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.