Search code examples
djangodjango-adminwagtaildjango-cmswagtail-admin

How can I create children of a non-existent parent page in the Wagtail CMS for Django?


I want to create children of a page (such as "/questions/example"), without having to create the root page "/questions". Is there a quick way of implementing something like this?


Solution

  • Child pages need to be, well, children - so there's no easy way to get around this.

    However, if what you're asking is "I want to have /questions/foo/ without having to have a page accessible at /questions/", two options are:

    1. add a new QuestionsPage to your project, add it as a child of the root, save as a draft and don't publish it - you'll then be able to add child pages to it and publish those, but anyone going to /questions/ will get a 404. This 'works' but isn't super-nice

    2. add a StructuralPage (or similar naming) to your project, and override the serve() and serve_preview() methods to redirect to the homepage (or somewhere else) if someone accesses them. You can add child pages to that, etc, as above.