I set up an example multipage app, using pages_folder
.
backend
---> __init__.py
---> applcation.py
pages
---> home_page.py
---> not_found_404.py
---> page2.py
run.py
backend/init.py:
from .application import app
backend/application.py:
from dash import Dash, html, dcc
import dash
pages_folder = '../pages'
app = Dash(__name__,
use_pages=True,
pages_folder=pages_folder)
app.layout = html.Div([
dash.page_container
])
pages/home_page.py:
import dash
from dash import html, dcc
dash.register_page(__name__, path='/')
layout = html.Div('Home page')
pages/page2.py:
import dash
from dash import html, dcc, callback, Input, Output
dash.register_page(__name__)
layout = html.Div('Page2!!')
pages/not_found_404.py:
from dash import html
import dash
dash.register_page(__name__)
layout = html.H1("This is a custom 404 page that does not work")
run.py:
from backend import app
if __name__ == '__main__':
app.run_server(debug=True)
When I move the dash app in such a way, that I do not need to set path_pages
, it does work as expected.
I was thinking, that the relative path in path_pages
could be responsible for that behavior.
Weirdly, when setting pages_folder=os.getcwd() + '/pages'
, I get an error message with
A folder called … does not exist.
While when trying to set assets_folder=os.getcwd + '/custom_assets'
, it works.
This means, pages_folder
and assets_folder
work differently. The former can only handle relative paths while the latter can also work with absolute ones? This seems odd to me
This seems to be connected to Bug - cannot register not_found_404 with dash.register_page() - #6 by jinnyzor
Should I open a bug report in git?