Learn Wagtail CMS Course

Headless CMS: Image Rendition Field

The Code

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")),
    ]

The Git Commit