Imagine that you are developing a blog overview page, and for each post you want to show images, music, or videos in that page taken from the content. In such a case, you need to extract the <figure>, <img>, <object>, <embed>, <video>, <audio>, and <iframe> tags from the HTML content of the post, as stored on a field of the post model. In this recipe, we will see how to perform this using regular expressions in the first_media filter.
Creating a template filter to extract the first media object
Getting ready
We will start with the utils app that should be set in INSTALLED_APPS in the settings and the templatetags package in this app.