Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix custom 404 page error in multi page application #2292

Merged
merged 4 commits into from
Nov 2, 2022
Merged

fix custom 404 page error in multi page application #2292

merged 4 commits into from
Nov 2, 2022

Conversation

Divyessh
Copy link
Contributor

@Divyessh Divyessh commented Oct 28, 2022

Start with a description of this PR. Then edit the list below to the items that make sense for your PR scope, and check off the boxes as you go!

Problem Faced

The issue comes up when trying to set up a custom not_found_404 page in a multi-page setup where the pages folder is not a direct subdirectory in the application root folder. In the example below, the dash will not use not_found_404.py as the custom 404 page.

Example

The file structure is as follows

.
|-- application.py
|-- requirements.txt
`-- src
    |-- __init__.py
    |-- assets
    |   |-- favicon.ico
    |-- pages
    |   |-- callbacks
    |   |   `-- sample_callback.py
    |   |-- layouts
    |   |   `-- sample_layout.py
    |   |-- not_found_404.py
    |   `-- procs
    |       `-- sample_proc
    |           `-- sample_proc.py

application.py

app = dash.Dash(
    __name__,
    server=server,
    use_pages=True,
    pages_folder='src/pages',
    assets_folder='src/assets',
    suppress_callback_exceptions=True,
)

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • task 1 - fix custom 404 page error in multi page application
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

@alexcjohnson
Copy link
Collaborator

@Divyessh thanks for catching this bug, and for opening this PR! I wonder whether we can be even more flexible and pick up a 404 page wherever it's registered, as long as it's called not_found_404? Something like:

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

@AnnMarieW any thoughts?

@AnnMarieW
Copy link
Collaborator

@alexcjohnson - oh of course- that would be the ideal solution. It would pick it up even if there was no pages folder.

@Divyessh Nice catch and thanks again for the PR!

@Divyessh
Copy link
Contributor Author

Divyessh commented Nov 1, 2022

@alexcjohnson @AnnMarieW
Thank You!
Sure, Let me implement these changes to the PR and add a commit.

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 Excellent, thanks again @Divyessh!

@alexcjohnson alexcjohnson merged commit 6921d34 into plotly:dev Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants