New Wagtail Course! 🥳 The Ultimate Wagtail Developers Course

Tutorial Wagtail Version: 2.x

Headless CMS: Image Rendition Field

In the previous lesson we created a custom Django Rest Framework Serializer to output JSONified image data in the Wagtail v2 API, including the URL, title, height and width. In this tutorial I'll show you how to to do the same thing but in one line of code using a built in Wagtail class.

This is actually so easy to do, it's hard to write a tutorial for it. So I'm going to leave this tutorial as a chunk of code (mainly) and if you need more details, this tutorials video, along with the previous video, will give you everything you need to create a successful Image Rendition in your Wagtail v2 API output.

``` from wagtail.api import APIField from wagtail.images.api.fields import ImageRenditionField # api_fields lives in an Orderable class, or a Page class. api_fields = [ # ... APIField("image", serializer=ImageRenditionField('fill-200x250', source="class_property_name")), ] ```

Related tutorials

The Ultimate Wagtail Developers Course

This course covers everything from basic installation to advanced features like custom blocks and API integration, it's perfect for developers looking to enhance their skills with this powerful CMS.

Ultimate Wagtail Developers Course Logo