Tutorial Wagtail Version: 2.x
Wagtail comes with a lot of really powerful features. Many features are not enabled by default as to keep your site running quickly and efficiently. One of those amazing features is the Wagtail v2 API, which can return any page, image, document, orderable and StreamField as a JSON response for your SPA/PWA to consume. We'll enable this by adding just 12 lines of code to our Wagtail CMS website.
You've undoubtedly stumbled across a website that's fluid and smooth. Pages transition without any flashing. And everything seems to be loading dynamically. Well, that's a progressive web app (PWA) or single page application (SPA). It acts as if it's an application on your mobile device. But in reality, it's just a website wearing a really good disguise.
The first step you'll need to take to start creating a PWA is enabling Wagtails existing support for a JSONified output. This is actually very easy to do. Let's install the existing apps.
Open your base.py
file and add the following lines to your INSTALLED_APPS
If you're starting a new (or close-to-new) project, you shouldn't already have an api.py
file. If you don't, make a new file beside urls.py
and name it api.py
. Then add the following code.
I mentioned this file should be beside your urls.py
file, but it doesn't need to be, it just makes the next step 1% easier.
Lastly, we need to add 2 lines to our urls.py file.
To access your API, you'll need to open http://localhost:8000/api/v2/pages/. This is your list view of all your Wagtail pages. At this point, your custom fields will not show up, just the default Wagtail Page fields will show up.
Want to see the entire Git Commit? No problem. The link to the Git Commit here will show you all 12 lines we added to our Wagtail website.
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: 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 Workshop (with Vue.js)
Posted on
Learn how to create a headless Wagtail website using Vue.js — from scratch
How to Create a Custom Wagtail Menu System
Posted on
Almost every website has some form of navigation. Wagtail websites are no different. But creating a menu isn't as easy as making top level pages (although that's an option!). In this tutorial we're going to explore how to create a Menu System using a Clusterable Model, an Oderable, a Snippet, and a custom template tag.. 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.