Headless CMS: Image Rendition Field
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
The entire git commit for this tutorial can be found here https://github.com/CodingForEverybody/learn-wagtail/commit/ec1b75b40d05f8b48b3bcfedfaa762bc751646e1
Was this helpful to you?
Sharing is caring. Help the community by sharing this article.