Tutorial Wagtail Version: 2.x
In this tutorial you will learn how to add Orderable model fields to your Wagtail v2 API, and how to add StreamFields to your API response. As with everything in Wagtail, this is a simple task for developers.
In previous tutorials we've learned how to enable the Wagtail v2 API so we can create a headless CMS, we learned how to expose our custom model fields, and we learned how to fetch specific fields from the API using only our URL bar.
But we didn't learn how to expose StreamFields or custom model fields from inside an Orderable.
In this video we'll learn how to do both of these.
Enabling StreamField API output is super simple. It's a subject I forgot to cover in an early lesson, but it's so simple we can cover this at any point in time because it's the exact same as exposing a custom model field, which we have explored in depth already.
Adding an Orderable to your API output is a bit more work, but honestly it's not very much work either. The main thing to note is that you need to add api_fields
to your main Page model, and also your Orderable.
By adding api_fields to your Page model, you're telling the API to link to the Orderable. But by default the Orderable does not have custom fields exposed, so we need to expose them by adding api_fields
to the Orderable. A blog-based example can be found below (or view the gist for a quick overview)
Headless CMS: Fetching Data From the v2 API
Posted on
The Wagtail v2 API is how we can turn our website into a Headless CMS. By default Wagtail will give you specific fields in the form a JSON object. But there are times when you only want certain fields; you might want to exclude or include specific fields in the JSON response. In this tutorial, we'll explore exactly how to do that.
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.
Headless CMS: Serializing Child Pages (and QuerySets)
Posted on
In this video we'll add all the blog pages to the blog listing page API response. This can be very helpful for Listing-style pages in your Headless Wagtail website.
Headless Workshop (with Vue.js)
Posted on
Learn how to create a headless Wagtail website using Vue.js — from scratch
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.