Paul
Paul

Reputation: 45

How can I use Wagtail Forms for a Headless CMS? ( without Template )

According to the documentation, Wagtail API is read-only ( POST Method not allowed ). Hence, the only way to use Forms from the Sidebar Menu is using Templates, so the client is capable of making post requests against the API internaly. But that´s not headless. To be headless the API must be capable of receiving form data by providing a URL.

Wagtail Docs - API

"The Wagtail API module exposes a public, read only, JSON-formatted API which can be used by external clients (such as a mobile app) or the site’s frontend."

...

At this point I´m not having the slightest clue, that means at a last resort I have to rethink my stack, although so far I have been very satisfied with Wagtail as headless CMS together with Nuxt as Client. Any ideas to avoid this measure would be much apprechiated.

Update - Nuxt POST Request to Wagtail API v2

pages/index.vue

<template>
...
</template>

<script>
export default {
  components: {
  },
  async asyncData ({ $axios, req }) {
    const pageHome = await $axios.$get('https://foo.bar.com/api/v2/pages/3/')
    return { pageHome }
  }
</script>

Upvotes: 2

Views: 1238

Answers (1)

Isaac T Chikutukutu
Isaac T Chikutukutu

Reputation: 426

I like the depth of you research but don't think you necessarily have to take a complete turn on your stack. I use exactly the same technologies but on forms you have to just use plain of Django Rest Framework serializers & generic class based views to handle common cases like ListCreateAPIView and RetrieveUpdateDestroyAPIView for heavy lifting.

Even though this approach involves quite a bit of coding you'll still be much better off writing your own API views to handle form data and there's no new plugins needed to pull it off.

Afterthought, if you need to have form attachments you can use this flexible method of creating your form model and to get your form responses in excel or csv you can use Django Admin Import/Export.

I hope this eliminates the need for you to throw away the baby & bath water.

Upvotes: 1

Related Questions