From adc2ea6a865bc6d771bdbad33943fdc7c4362fec Mon Sep 17 00:00:00 2001 From: Tibor Leupold Date: Thu, 16 Jun 2022 07:06:09 -0700 Subject: [PATCH] Use RichText object for adding rich text blocks (#8675) I have just tried to follow the original instructions and got an `AttributeError: 'str' object has no attribute 'source'` when trying to append a rich text block to a `StreamField` programmatically. Wrapping the value in a `RichText` object solved the issue. This seems to be in line with the behavior described further down the page. --- docs/topics/streamfield.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/topics/streamfield.rst b/docs/topics/streamfield.rst index ad99504ffb..3a16f8913e 100644 --- a/docs/topics/streamfield.rst +++ b/docs/topics/streamfield.rst @@ -536,8 +536,9 @@ A StreamField's value behaves as a list, and blocks can be inserted, overwritten # Delete the last block del my_page.body[-1] - # Append a block to the stream - my_page.body.append(('paragraph', "

And they all lived happily ever after.

")) + # Append a rich text block to the stream + from wagtail.rich_text import RichText + my_page.body.append(('paragraph', RichText("

And they all lived happily ever after.

"))) # Save the updated data back to the database my_page.save()