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 Mastering Flask 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.