I'm using Wagtail's after_create_page
and after_edit_page
hooks to push data to an external service, and I'd like to display an error or success message depending on the response. Is there a way to hook into the flash messages that appear after publishing a page?
Asked
Active
Viewed 453 times
0

Noah Manger
- 31
- 3
1 Answers
0
You could use the Wagtail internal messages API as part of your wagtail_hook
. This is not documented but I have tested it with the Wagtaildemo application locally.
Wagtail messages API takes a request object and can be used to render success/error/warning messages alongside that request's response.
All messages appear to be append only, so your error message would appear under the success message from the page being created.
Example code below.
# my_aap/wagtail_hooks.py
from wagtail.wagtailcore import hooks
from wagtail.wagtailadmin import messages
@hooks.register('after_edit_page')
def do_after_page_edit(request, page):
messages.success(request, "Looking good")
@hooks.register('after_create_page')
def do_after_page_create(request, page):
messages.error(request, "Failed to send items to external server")
These messages will not affect the overall HTTP response of the edit or create page response views.
You can also see how the internal messages API is used when creating and editing pages at wagtailadmin/views/pages.py. You can even create buttons on messages pretty easily.

LB Ben Johnston
- 4,751
- 13
- 29