New Wagtail Course! 🥳 The Ultimate Wagtail Developers Course

Tutorial Wagtail Version: 2.x

Headless CMS: Custom Page Properties

If you want to add data custom data (or a function output) to your headless Wagtail API, you can use a @property. In this tutorial I'll show you how easy it can be!

``` from wagtail.api import APIField from wagtail.core.models import Page class YourPage(Page): # .. Page fields # Your api fields api_fields = [ # ... api fields APIField("a_custom_api_response"), ] @property def a_custom_api_response(self): # Possible custom logic can go in here # ¯\_(ツ)_/¯ return "Return a custom thing (string, list, dictionary, etc)" ```

Related tutorials

Headless CMS: Custom Wagtail Image Serializer

Posted on

Using Django Rest Framework with Wagtails v2 API, we can customize ANY field the way we want. In this short video, we take a look at creating a new field entirely by overwriting an image, but we also look at serializing (JSONifying) an image field from a ForeignKey inside an Orderable. Don't worry, it's not as crazy as it sounds!

View lesson, Headless CMS: Custom Wagtail Image Serializer

Headless CMS: Exposing Custom Page Fields to the v2 API

Posted on

In the last lesson we enabled Wagtails v2 API but we didn't have access to our custom fields.. yet! In this lesson we'll learn how in just 4 lines of code we can make a custom Wagtail Page field show up in our API. And it only gets easier from there.

View lesson, Headless CMS: Exposing Custom Page Fields to the v2 API

Headless CMS: Serialize a Custom Image Chooser Block

Posted on

Learn how to serialize an ImageChooserBlock in your StreamFields to output the image data you're looking for.

View lesson, Headless CMS: Serialize a Custom Image Chooser Block

Getting Child Page Properties From a Subclassed Page

Posted on

In Wagtail, and just like in Django, you can subclass classes. In this lesson, we're subclassing a Wagtail Page into 2 child pages. But when we query for all the parent classes, we're also given the child classes in the QuerySet, and the data is somewhat inconsistent because child classes can have unique fields that differ from their parents and siblings.

View lesson, Getting Child Page Properties From a Subclassed Page

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