Frappe website catch all

Adding fallback page in frappe

Goal

This post explains how we can serve a fallback page instead of serving the default 404 when path can’t be resolved.

Frappe installation provides several routes by default. Some of them are /about /contact, /newsletters etc.

You might want your about page to be served when path provided by user cannot be resolved.

Setup

This post assumes that you have bench initialized and you are able to add a site to your frappe installation.

Let’s add a site

$ bench new-site foo.bar

Default behaviour

If you access foo.bar:8000/some-random-url, you would see a 404 page.

Adding rules

There is a hookpoint called website_catch_all in hooks.py which allows setting a fallback path.

Create an app so that we have a hooks.py where we can add route.

$ bench new-app meeting # You could use any app name
$ bench --site foo.bar install-app meeting

Add a module level attribute website_catch_all in meeting/meeting/hooks.py

website_catch_all = ['about']

This would ensure that the About page is served in case the url cannot be resolved to a valid path.

Thank you for reading the Agiliq blog. This article was written by Akshar on Aug 14, 2018 in pythonfrappeerpnext .

You can subscribe ⚛ to our blog.

We love building amazing apps for web and mobile for our clients. If you are looking for development help, contact us today ✉.

Would you like to download 10+ free Django and Python books? Get them here