Tutorial Summary

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")),
Sign up for our newsletter

Get notified about new lessons :)

Our Sites