New Wagtail Course! 🥳 The Ultimate Wagtail Developers Course

Tutorial Wagtail Version: 2.x

StreamField Deep Dive: How to find undocumented options

The Wagtail docs can't possibly cover everything, that's pretty unrealistic to expect perfect documentation. So in this video I will show you how to explore StreamField options that aren't always available in the documentation. You can apply what you'll learn in this video to any feature in Python, but we're using StreamFields as an example. Let's learn how to dive into a core feature of Wagtail!

Writing a StreamField without a custom class

For simple StreamFields you do not need to create custom classes. If you want to, that's 100% OK to do. Below you will see an example of a CharBlock that uses most of the available CharBlock kwargs.

``` from wagtail.core.fields import StreamField from wagtail.core.models import Page from wagtail.core import blocks as streamfield_blocks class FlexPage(Page): """Flexible page class.""" content = StreamField( [ ("char_block", streamfield_blocks.CharBlock( required=True, help_text="Oh wow this is help text!!", min_length=10, max_length=50, template="streams/char_block.html", )) ], null=True, blank=True, ) ```

If you're wondering how I know we can use these fields:

  • required
  • help_text
  • min_length
  • max_length
  • template

Well the TL;DR version is: I went to the source code https://github.com/wagtail/wagtail/blob/master/wagtail/core/blocks/field_block.py#L97

If you want to know how I found this, you'll need to watch the video and about half way through I start talking about how to find the source code by working backwards from my current code.

The Git Commit

Take a look at all the code I wrote in this tutorial: https://github.com/CodingForEverybody/learn-wagtail/commit/261adec1f07a4fe74f53610b69418b5f52484240

Related tutorials

StreamField Deep Dive 2: Exploring Common StreamFields

Posted on

We'll dive into most of the simple StreamFields and explore some of the options they have to offer. We'll also look at ChooserBlock inheritance for the PageChooserBlock, ImageChooserBlock and DocumentChooserBlock.

View lesson, StreamField Deep Dive 2: Exploring Common StreamFields

How to Use ListBlocks to Create Repeating StreamField Content

Posted on

Occasionally you'll want a StreamField that can have multiple repeating content areas. A good example is the design component known as a Card. In this lesson we'll explore a ListBlock to enable us to create unlimited cards with custom data, ImageChooserBlock, PageChooserBlock and how to loop through a ListBlock in your Wagtail CMS template.

View lesson, How to Use ListBlocks to Create Repeating StreamField Content

How to Add a Basic StreamField to your Wagtail CMS Page

Posted on

In this lesson we are going to learn how to add a basic StreamField to a a generic Wagtail CMS Page. We'll create a new app from scratch, and this StreamField will have a title and text (using StructBlock), a custom template, and it will lay the foundation for the next lesson which covers inheriting RichTextBlock and modifying the features it can have.

View lesson, How to Add a Basic StreamField to your Wagtail CMS Page

How to Add a RichText StreamField to your Wagtail CMS Page

Posted on

In this video we are going to learn how to create a RichTextBlock StreamField, and then we're going to duplicate that StreamField and limit the number of features the editor gives us.

View lesson, How to Add a RichText StreamField to your Wagtail CMS 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