Wagtail CMS
Wagtail is an open-source content management system (CMS) built on the Django framework, known for its intuitive content editing interface and flexible development architecture. It is currently at version 7.3.1 and follows a regular release cadence with major versions typically released annually, accompanied by frequent patch and minor releases addressing bug fixes and security updates.
Warnings
- breaking The `wagtail.core` module was deprecated and removed in Wagtail 3.0+. Core components like `Page`, `Site`, `StreamField`, and `Image` were moved to more specific modules.
- breaking The `wagtail.admin.edit_handlers` module was removed and replaced by `wagtail.admin.panels` in Wagtail 3.0+. Panel classes (`FieldPanel`, `MultiFieldPanel`, etc.) and their API have changed significantly.
- breaking For `StreamField` definitions, `use_json_field=True` is now the default and implicitly required for new fields in Wagtail 3.0+. Projects upgrading from older versions where `StreamField` might have used a different underlying storage may require manual data migrations.
- gotcha Wagtail has strict requirements on the supported Django versions for each major release. Using an unsupported Django version will lead to integration issues, runtime errors, or unexpected behavior.
- gotcha When rendering `StreamField` content in templates, ensure you correctly use Wagtail's template tags like `{% include_block %}` or `{{ self.body|richtext }}`. Custom block templates need careful setup, and direct iteration over `StreamField` values may not provide the full block context for rich rendering.
Install
-
pip install wagtail
Imports
- Page
from wagtail.models import Page
- StreamField
from wagtail.fields import StreamField
- blocks
from wagtail import blocks
- FieldPanel
from wagtail.admin.panels import FieldPanel
Quickstart
from django.db import models
from wagtail.models import Page
from wagtail.fields import StreamField
from wagtail import blocks
from wagtail.admin.panels import FieldPanel
class HomePage(Page):
"""
A simple example of a Wagtail Page model with a StreamField.
This defines a flexible content structure editable in the Wagtail admin.
"""
body = StreamField([
('heading', blocks.CharBlock(form_classname="full title")), # Simple text block
('paragraph', blocks.RichTextBlock()), # Rich text editor
('image', blocks.ImageChooserBlock()), # Image picker
('embed', blocks.RawHTMLBlock(icon='code')), # Raw HTML embed
], use_json_field=True, blank=True, null=True)
# Define the fields that will appear in the Wagtail admin editor
content_panels = Page.content_panels + [
FieldPanel('body'),
]
# You would typically also define a template (e.g., home/home_page.html)
# and potentially an `abstract` page for common fields across your site.