From 4c66722af69004ffcb81fae3424d918b18306567 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Wed, 29 Jul 2026 10:36:34 +0200 Subject: [PATCH] Load DJP plugin urls before Wagtails urls. --- docs/references/plugins.md | 10 ++++++++++ hypha/urls.py | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/references/plugins.md b/docs/references/plugins.md index b24e04349b..3d59b60a2d 100644 --- a/docs/references/plugins.md +++ b/docs/references/plugins.md @@ -7,3 +7,13 @@ See https://djp.readthedocs.io/ for more information. You can set the `DJP_PLUGINS_DIR` environment variable to point to a directory which contains *.py files implementing plugins. Good for development and when you do not want to publish the plugin on PyPI. Since DJP allow a plugin to override any setting you can tell Hypha to look for templates in a directory inside your plugin. This allows the plugin to override any template in Hypha. + +## URL ordering + +URLs contributed through the DJP `urlpatterns()` hook are added to the root urlconf **after** Hypha's own routes but **before** Wagtail's page-serving catch-all (`path("", include(wagtail_urls))`). This means: + +- A plugin **cannot** shadow a core Hypha URL (e.g. `apply/`, `admin/`, `account/`) — core routes are matched first. +- A plugin URL **is** reachable even when it is slug-shaped (e.g. `account/country/`). Wagtail's catch-all would otherwise match any such path and return a 404 (*"The current path … matched the last one."*), so plugin URLs are deliberately placed ahead of it. +- A plugin URL takes precedence over a Wagtail page at the same path. + +Prefer the `urlpatterns()` hook for adding routes. Only manipulate the root urlconf directly (e.g. from `AppConfig.ready()`) if you need finer control than the hook provides. diff --git a/hypha/urls.py b/hypha/urls.py index 6323c09c5b..e910e6010c 100644 --- a/hypha/urls.py +++ b/hypha/urls.py @@ -108,13 +108,14 @@ ), ] +# Load urls from any djp plugins. +urlpatterns += djp.urlpatterns() + +# Need to be last. urlpatterns += [ path("", include(wagtail_urls)), ] -# Load urls from any djp plugins. -urlpatterns += djp.urlpatterns() - if settings.DEBUG: import debug_toolbar