How to use ui.add_static_files when using @ui.page("/{_:path}") with sub_pages? #6119
First Check
Example Code#!/usr/bin/env python3
from custom_sub_pages import custom_sub_pages, protected
from nicegui import app, ui
@ui.page('/')
@ui.page('/{_:path}')
def main_page():
pass
if __name__ in {'__main__', '__mp_main__'}:
app.add_static_files(url_path="/files", local_directory=FILES_PATH)
ui.run(storage_secret='demo_secret_key_change_in_production')DescriptionThis is the same code as in https://github.com/zauberzeug/nicegui/tree/main/examples/single_page_app. However, adding a static file route does not work, it is hijacked by the catchall route in the I tried to add the static route inside How do I add a static file route in this case? NiceGUI Version3.12.1 Python Version3.14.5 BrowserFirefox Operating SystemLinux Additional ContextNo response |
Answered by
python-and-novella
Jun 18, 2026
Replies: 1 comment 3 replies
|
Try this: from nicegui import app, ui
app.add_static_files(url_path="/files", local_directory='./')
@ui.page('/')
@ui.page('/{_:path}')
def main_page():
pass
if __name__ in {'__main__', '__mp_main__'}:
ui.run(storage_secret='demo_secret_key_change_in_production') |
3 replies
Answer selected by
quartelmestre
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this: