Bug - Dash Pages does not find pages with underscores

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