What Wagtail is
Wagtail is a content management system built on Django. Editors get a page tree, preview, revisions and scheduled publishing. Developers write ordinary Django models that inherit Page, plus templates.
| Question | Answer in Wagtail |
|---|---|
| Where is the URL? | the path through the page tree |
| Where is the structure? | the model and its panels |
| Where is the look? | the page template |
Creating a project
pip install wagtail
wagtail start mysite
cd mysite
pip install -r requirements.txt
python manage.py migrate
python manage.py createsuperuser
python manage.py runserverwagtail start generates a project with home and search apps. The Wagtail admin is at /admin/.
💡 Wagtail is a normal Django project:
settings.py,urls.py, migrations and the ORM work as you know them.
Page models and the tree
# blog/models.py
from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page
class BlogPage(Page):
date = models.DateField("Post date")
intro = models.CharField(max_length=250)
body = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel("date"),
FieldPanel("intro"),
FieldPanel("body"),
]content_panels defines the editor form. Restrict where a page may live with parent_page_types and subpage_types:
# blog/models.py
from wagtail.models import Page
class BlogIndexPage(Page):
subpage_types = ["blog.BlogPage"]