Bug - Dash Pages does not find pages with underscores

Defining two pages using the new Dash Pages functionality:

dash.register_page("mypage",  layout=html.Div('mypage'))
dash.register_page("my_page",  layout=html.Div('my_page'))

The first one operates as expected, however the second one (or any page with an underscore character) gets a 404 - Not found

This should either be fixed or documented. I see no note to this effect within Multi-Page Apps and URL Support | Dash for Python Documentation | Plotly

1 Like

Hi @marketemp

I agree that the docs could be more clear about how Pages creates the dash.page_registry

If you don’t define certain props, they will be generated for you.

For example, if you don’t specify a path, then it’s inferred from the module name. It’s a convention (and can help with SEO) that path names have dashes rather than underscores, so if your module name is “my_page”, it will generate path="/my-page". If you prefer to use underscores in the path, than you can specify path="/my_page"

When you are debugging a Pages app, it’s handy to inspect the dash.page_registry. There is a utility in dash-labs that pretty prints the registry. You can find more info here

Here’s an example:


from dash import Dash, html, register_page, page_container

# must use dash-labs>=1.1.0
from dash_labs import print_registry

app = Dash(__name__, use_pages=True, pages_folder="")

register_page("my_page", layout=html.Div("my_page"), path="/my_page")
register_page("my_home_page", layout=html.Div("my_home_page"))

print_registry()

app.layout = html.Div(page_container)

if __name__ == "__main__":
    app.run_server(debug=True)



This is what gets printed to the console - take a look a the path props

{'my_home_page': {'module': 'my_home_page',
                  'supplied_path': None,
                  'path_template': None,
                  'path': '/my-home-page',
                  'supplied_name': None,
                  'name': 'My home page',
                  'supplied_title': None,
                  'title': 'My home page',
                  'description': '',
                  'order': None,
                  'supplied_order': None,
                  'supplied_layout': Div('my_home_page'),
                  'supplied_image': None,
                  'image': None,
                  'image_url': None,
                  'redirect_from': None,
                  'layout': Div('my_home_page'),
                  'relative_path': '/my-home-page'},
 'my_page': {'module': 'my_page',
             'supplied_path': '/my_page',
             'path_template': None,
             'path': '/my_page',
             'supplied_name': None,
             'name': 'My page',
             'supplied_title': None,
             'title': 'My page',
             'description': '',
             'order': None,
             'supplied_order': None,
             'supplied_layout': Div('my_page'),
             'supplied_image': None,
             'image': None,
             'image_url': None,
             'redirect_from': None,
             'layout': Div('my_page'),
             'relative_path': '/my_page'}}

If you are just getting started with Pages, I recommend this repo - you’ll find lots of minimal working examles

1 Like

Thanks @AnnMarieW I was able to get things working most effectively by simply not using underscores complete within my page names. This definitely should be documented on Multi-Page Apps and URL Support | Dash for Python Documentation | Plotly

As mentioned in the other topic, it’s common to use underscores in file name - there are several examples both in the docs and in the repo I recommended.

that seems to interfere with the declaration of custom 404 pages: Bug - cannot register not_found_404 with dash.register_page() - #7 by luggie

as described here: Multi-Page Apps and URL Support | Dash for Python Documentation | Plotly