From 80f668b04cd8bce518afc318f73da6dc9a1eb94c Mon Sep 17 00:00:00 2001 From: Divyessh Maheshwari Date: Fri, 28 Oct 2022 17:41:32 +0530 Subject: [PATCH 1/3] fix custom 404 page error in multi page application --- dash/dash.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dash/dash.py b/dash/dash.py index 11855ce584..98cd13509b 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -2064,7 +2064,14 @@ def update(pathname, search): # get layout if page == {}: module_404 = ( - ".".join([self.pages_folder, "not_found_404"]) + ".".join( + [ + self.pages_folder.replace("\\", "/") + .lstrip("/") + .replace("/", "."), + "not_found_404", + ] + ) if self.pages_folder else "not_found_404" ) From bd7cbce4009c46e7749f2d9b0c54930f8fa82547 Mon Sep 17 00:00:00 2001 From: Divyessh Maheshwari Date: Wed, 2 Nov 2022 06:32:03 +0530 Subject: [PATCH 2/3] Add suggested modification --- dash/dash.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 98cd13509b..239d59e773 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -2063,22 +2063,11 @@ def update(pathname, search): # get layout if page == {}: - module_404 = ( - ".".join( - [ - self.pages_folder.replace("\\", "/") - .lstrip("/") - .replace("/", "."), - "not_found_404", - ] - ) - if self.pages_folder - else "not_found_404" - ) - not_found_404 = _pages.PAGE_REGISTRY.get(module_404) - if not_found_404: - layout = not_found_404["layout"] - title = not_found_404["title"] + for module, page in _pages.PAGE_REGISTRY.items(): + if module.split(".")[-1] == "not_found_404": + layout = page["layout"] + title = page["title"] + break else: layout = html.H1("404 - Page not found") title = self.title From 93c9de19551755753929e1f2af26ef33ef9fc431 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Wed, 2 Nov 2022 11:14:27 -0400 Subject: [PATCH 3/3] changelog for pages 404 fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2894d0ecf5..907e3ba438 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed +- [#2292](https://github.com/plotly/dash/pull/2292) Pages: find the 404 page even if `pages_folder` is nested, or the 404 page is nested inside `pages_folder`. - [#2265](https://github.com/plotly/dash/pull/2265) Removed deprecated `before_first_request` as reported in [#2177](https://github.com/plotly/dash/issues/2177). - [#2257](https://github.com/plotly/dash/pull/2257) Fix tuple types in the TypeScript component generator.