DEV Community

Praise Agbabiaka
Praise Agbabiaka

Posted on • Edited on

Building My First Wagtail Site

Software development is an ever-changing field. Often, one has to pick up new technologies rather quickly. This was the case for me with Wagtail. And thanks to its simplicity, I was able to do so in no time.

Why Wagtail?

An opportunity to improve the accessibility of websites built with Wagtail opened up recently. And I immediately jumped on it. I was so excited at the prospect of putting my accessibility skills to use that I didn’t give much thought to the fact that I had no experience with Wagtail. I figured I could pick up Wagtail quickly enough if I put my mind to it. And since I learn best by doing, I decided to build a blog site to gain hands-on experience with Wagtail.

What’s Wagtail?

Wagtail is an open-source Content Management System built on Django. So, much of the process for building websites with Django translates directly to Wagtail. But Wagtail abstracts the need to define urls, views and admin functionality. In Wagtail, emphasis is placed on page and page content. Every page is built from a Django model that inherits from Wagtail’s Page model. Wagtail also provides a number of custom template tags and filters that extend the capabilities of the Django templating engine.

Building the Blog Site

I decided that my blog site would have a home page, a blog index page, blog post pages, and an about page. Since a home app comes out of the box with Wagtail, I only had to create a base and blog app for my Wagtail project.

In the home app, I updated the HomePage model to include fields for a hero image, heading, introduction and link to the blog index page. I defined the image and link fields as a Foreignkey to Wagtail’s Image and Page models, respectively.

As the name suggests, the base app defined functionalities shared across apps within the project. It contained snippets for the site logo, main menu and breadcrumb navigation. Within this app, I constructed a ContentBlock that allowed me to dynamically add subheading, image, list and rich text content to a page. This ContentBlock inherited from StreamBlock. It was used to define a StreamField to populate the body field of the about and blog post pages. Because the about page didn’t belong in the home or blog app, I defined a StandardPage model to create it.

The blog app held models and templates for the blog index page and blog post pages. I defined the BlogPage model as child page of the BlogIndexPage. And I populated the blog index page with meta data for each blog post. Thus, a new blog site was built.

I’m glad that I can now add Wagtail to my toolkit as a web developer. If you’d like to see my code, check out the praiztech_blog repository on GitHub. I'm still working on the front-end, though.

Top comments (0)