Using Wagtail as an API layer
Asked Answered
A

1

9

My company is evaluating Wagtail as a CMS for parts of our website. Currently we're running Python 2.7 and Django 1.5 (don't ask...). We have the ability to run Wagtail on a separate instance which can include the most current versions of Python/Django but we will not be able to run Wagtail out of the box within our main application.

We're looking at using Wagtail strictly as a CMS, then proxying requests from our main website to the Wagtail instance and returning just the generated markup.

Is there anyone who has done something like this, of could offer insight into the process we might take? Does Wagtail offer functionality like this out of the box? What potential pitfalls might we encounter, or things we should watch out for?

This could mean that instead of "entire pages" stored in Wagtail, we treat it as a way to store distinct content fragments: A paragraph of text which would be loaded into our homepage, or the outer wrapper of a dynamic search results page.

Adigun answered 3/7, 2018 at 13:40 Comment(0)
S
9

Yes, Wagtail does offer functionality like this, via its API:

http://docs.wagtail.io/en/v2.1/advanced_topics/api/

You could consume the API from the front-end of your main website, using JavaScript (React and Vue are popular options for this approach, but they aren't necessary if you don't need a complex Single Page Application with routing etc), or from the back-end, making HTTP requests from the views of your Django 1.5 app.

As for potential pitfalls, the main issue is that Wagtail previews won't work out of the box, since Wagtail doesn't know about how the content will be rendered. If you have a predictable URL structure on the site that's rendering Wagtail API content, the preview mechanism can be configured to handle this.

If the API approach isn't what you have in mind, you could also consider ways of embedding rendered fragments in the main site. For example, if you use Varnish in front of the main site, you could take advantage of Edge Side Includes:

https://varnish-cache.org/docs/3.0/tutorial/esi.html

Finally, you may find this recent talk on Wagtail as a 'headless' CMS useful:

Sure answered 3/7, 2018 at 14:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.