O'Reilly logo

Mastering Flask by Jack Stouffer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required