Tutorial Summary

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

Get notified about new lessons :)


Our Sites