Things to know before getting started with wagtail
Tags: webdev, python, django, wagtail
Published: 2023-04-03 21:32:05

## Prelude

Wagtail is a CMS built upon Django. It inherits some of Django's major features including security and ease of use. The two frameworks thus share a lot of similarities. It helps to have knowledge of Django before deciding to learn wagtail. Even though it's possible to learn wagtail as a standalone framework.

Despite all their similarities there are some differences between the Wagtail and Django. What stands out most with wagtail is the emphasis placed on pages, and the content they contain.  And also the hierarchical relationship between pages. (i.e. the same kind of structure used in directories).
```  

└── home

    ├── blog

    │   ├── first_post

    │   └── second_post

    └── profiles

        └── profile1
```

![image showing the directory tree structure in the terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zg5tbgkjsu4o0bvjsdet.png)
Every [Page](https://medium.com/r/?url=https%3A%2F%2Fgithub.com%2Fwagtail%2Fwagtail%2Fblob%2Fdef7e44a380d9098541d4f266b9c211202d94150%2Fwagtail%2Fmodels%2F__init__.py%23L1069) type is a Django model and inherits from the [ClusterableModel](https://medium.com/r/?url=https%3A%2F%2Fgithub.com%2Fwagtail%2Fdjango-modelcluster%2Fblob%2Fbe42bbe179f92a383b21b52b94d5be47fda46cc4%2Fmodelcluster%2Fmodels.py%23L152). The ClusterableModel then inherits from Django's own model class. The image below displays the relationship between them:

![Inheritace diagram showing the relationship between the different classes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/802p6ooypmt9akv1a1he.png)

## All about pages

In wagtail pages host all the content. The Page model provided by wagtail abstracts away a lot of things. This makes it easier to create, and manage content. Some of these abstractions include:

* All pages are extensions of Django models. So it's possible to access all the functions and fields provided in the models and more. e.g `RichTextField` , `StreamField`
* Defining a page lets you define various editor panels. Such as: `content_panels`, `promote_panels`, and `settings_panels` for easy management in wagtail's admin panel
* Pages let you choose the HTML template to use for them
* And within the admin panel you can decide your page routes and their relationship to other pages. (i.e. parent, child pages)
* Wagtail improves the developer experience by combining functionality. The page types act as  `model` , `urls`, `views`, and `admin` classes provided in a typical Django project.
 
As it is with Django this ease of use comes at a cost. With so many things being handled internally it can seem like a black box, especially for someone who does not have a full grasp of the inner workings.
***
Some mistakes to avoid in your adoption of Wagtail:
- When creating Page objects with code you have to consider the page's relationships. Wagtail handles this when using the admin panel. As mentioned earlier the relationship between pages is important. More details in the stack overflow page below:. 
More details in the stack overflow page below:
{% embed https://stackoverflow.com/questions/55409667/creating-page-object-programmatically-got-error-validationerror-path-and-depth-f
 %}
- Make sure you pay attention to the slugs (routes) generated for your pages in the promote tab of the admin panel and modify them to suite to your needs
## Conclusion
To find out more about what's possible with wagtail check out the [docs](https://docs.wagtail.org/en/stable/index.html). Thanks for reading.