New Wagtail Course! 🥳 The Ultimate Wagtail Developers Course

Tutorial Wagtail Version: 2.x

How to Add a RichText StreamField to your Wagtail CMS Page

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.

Note: This is a 2 part video lesson. Part 1 will covered how to create a basic StreamField from scratch.

In this video we are going to explore how to add a RichTextBlock as a StreamField inside of an app called "streams". There are a number of ways to add a RichText StreamField to your pages, and we're covering a couple of the harder methods in this video.

``` # streams/blocks.py from wagtail.core import blocks class RichtextBlock(blocks.RichTextBlock): """Richtext with all the features.""" class Meta: # noqa template = "streams/richtext_block.html" icon = "doc-full" label = "Full RichText" class SimpleRichtextBlock(blocks.RichTextBlock): """Richtext without (limited) all the features.""" def __init__( self, required=True, help_text=None, editor="default", features=None, **kwargs ): # noqa super().__init__(**kwargs) self.features = ["bold", "italic", "link"] class Meta: # noqa template = "streams/richtext_block.html" icon = "edit" label = "Simple RichText" ```
``` # flex/models.py # ..... from streams import blocks.py class FlexPage(Page): # .... content = StreamField( [ ("title_and_text", blocks.TitleAndTextBlock()), ("full_richtext", blocks.RichtextBlock()), ("simple_richtext", blocks.SimpleRichtextBlock()), ], null=True, blank=True, ) ```
The Git Commit

If you're interested in seeing the entire commit for this video, all the source code is available here.

Related tutorials

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