Back

5 Tips to Streamline Your Wagtail CMS Development

Hi! I’m Patryk. I’m a Python Backend developer at Profil Software. In my work, I’ve had a chance to use Wagtail to build a few applications. It’s a free and open-source content management system written in Python that is based on Django. That makes it easy and speeds up development. In this article, I would like to share a few tips with you that came out of my work for Python Development Company. I hope that it will help you build Wagtail applications more efficiently.

Use explorer feature

Before creating any application, you should consider what your website would look like when it comes to the hierarchy of pages. Wagtail offers support for organizing your pages into folders and thus creating paths to them. You should avoid flat structure as it complicates using the admin panel because over time there can be a lot of pages and navigating between them can become problematic. Also, a well-designed page structure helps you to configure SEO for your pages.

You can force the user to follow your hierarchy by using parent_page_types and subpage_types properties in your page model. For a simple blog, I would create a hierarchy like this:

0_PCitZgFW7xg7LMgJ

We have a root. Each category has its page and generates the proper path. Each article belongs to a category.

Here is the code:

For images consider using `wagtail.images.models.imageField`

First of all, it has a wagtail panel that looks user-friendly. Another important feature is that you can add custom fields, for example, caption. You can find out here how you can do it. And last but not least, the model allows you to easily convert and scale images by using get_rendition method. For example, image.get_rendition(“fill-800x600|format-webp|webpquality-95”) produces a webp image with size 800x600 and quality 95 and saves it when trying to use it again.

Example code

And here is how it looks like

0_IuLcq15hynvIjzc9

StreamField for complex structure

When I was creating a blog application I had to create a post model with an extended content field. As you know, the field can contain anything, starting from GitHub gist, special styled links, and ending with a gallery. Unfortunately, the Wagtail rich text editor wasn’t sufficient. I found that there is a StreamField. After a few hours of studying, I managed to create a very nice-looking widget that the client could use and add all these fancy things. You just simply create “blocks” with desired fields and then include them in the StreamField. With this field, you can create very complex widgets. More about it here.

Example StreamField block

And the PostPage

Final result:

0_eLEFFcGHJJqb-UyM

And the AdBlock

0_bbwb_6Y8UCAcjNdG

When your page is too big, divide it into tabs

I created a home page. Initially, there were only a few things with content. Over time, It was growing and growing, and adding new content became problematic because finding a proper place to put new content took years. I had to scroll over all these inputs and search for the one I am looking for. I found that wagtail shares a feature that allows you to divide a page into tabs! After moving stuff around a little, it looked much better and more intuitive for users. Learn here how to do it.

Example code for dividing blog into tabs:

Final result:

0_eoQ4E3vPJKxtGlpW

Extra tip

Over the years, the Wagtail community was growing and thus many libraries were made that are extending the wagtail features. Founding the proper one can be challenging, and you don’t know what is available. I found the Github page where you can find most of them. Moreover, there are presentations, videos, podcasts, and many more materials.

0_Y15Nrage_3jPJ7Wb

That’s all the tips I wanted to share with you. I hope that you can use some of them to build better wagtail applications.

For other articles on Python you may refer to our software development blog from which you'll learn what is Django Rest Framework and how to effectively use it, why are Python metaclasses so special and more.

Wagtailcms
Python Programming
Software Development
wagtail
Profil Software stores cookies on your computer. These cookies are used to collect information about how you interact with our website and allow us to remember you.We use this information in order to improve and customize your browsing experience and for analytics and metrics about our visitors both on this website and other media. To find out more about the cookies we use, see our .