1
1
from dash import callback , Output , Input , html , dcc
2
2
import dash
3
3
import os
4
+ import glob
4
5
import importlib
5
6
from collections import OrderedDict
6
7
import json
@@ -223,18 +224,20 @@ def _filename_to_name(filename):
223
224
224
225
225
226
def _filename_to_path (filename ):
226
- return "/" + filename .split ( "." )[ - 1 ] .replace ("_ " , "- " ).lower ()
227
+ return filename .replace ( "_" , "-" ) .replace (". " , "/ " ).lower (). split ( "pages" )[ - 1 ]
227
228
228
229
229
230
def plug (app ):
230
231
# Import the pages so that the user doesn't have to.
231
232
# TODO - Do validate_layout in here too
232
233
dash .page_registry = OrderedDict ()
233
234
234
- for page_filename in os .listdir ("pages" ):
235
+ for page_filename in glob .iglob ("pages/**" , recursive = True ):
236
+ _ , _ , page_filename = page_filename .partition ("pages/" )
235
237
if page_filename .startswith ("_" ) or not page_filename .endswith (".py" ):
236
238
continue
237
239
page_filename = page_filename .replace (".py" , "" )
240
+ page_filename = page_filename .replace ("/" , "." )
238
241
page_module = importlib .import_module (f"pages.{ page_filename } " )
239
242
240
243
if f"pages.{ page_filename } " in dash .page_registry :
@@ -253,7 +256,6 @@ def router():
253
256
def update (pathname , search ):
254
257
path_id = app .strip_relative_path (pathname )
255
258
query_parameters = _parse_query_string (search )
256
-
257
259
layout = None
258
260
for module in dash .page_registry :
259
261
page = dash .page_registry [module ]
0 commit comments