Wagtail Contact Page ******************** - :doc:`dev-wagtail` - :doc:`dev-wagtail-plugins` .. highlight:: python From `Recipes - Overriding the serve() Method`_ .. note:: I updated the code to return a ``TemplateResponse`` because the type checking wasn't happy with the original code. :: from django.db import transaction from django.template.response import TemplateResponse from enquiry.forms import EnquiryForm from enquiry.models import Enquiry from gdpr.models import Consent class ContactPage(Page): def _consent(self): return Consent.objects.get_consent(Enquiry.GDPR_CONTACT_SLUG) def serve(self, request): context = super().get_context(request) kwargs = dict(consent=self._consent(), request=request) if request.method == "POST": form = EnquiryForm(request.POST, **kwargs) if form.is_valid(): with transaction.atomic(): enquiry = form.save() transaction.on_commit(lambda: process_mail.send()) context.update({"enquiry": enquiry, "page": self}) return TemplateResponse(request, self.template, context) else: form = EnquiryForm(**kwargs) context.update({"enquiry": None, "form": form, "page": self}) return TemplateResponse(request, self.template, context) .. _`Recipes - Overriding the serve() Method`: https://docs.wagtail.org/en/stable/reference/pages/model_recipes.html