Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui.image will never load local image in single page app example #3223

Closed
atticus-lv opened this issue Jun 14, 2024 · 6 comments
Closed

ui.image will never load local image in single page app example #3223

atticus-lv opened this issue Jun 14, 2024 · 6 comments

Comments

@atticus-lv
Copy link

atticus-lv commented Jun 14, 2024

Description

system: win11
nicegui: 1.4.27

code from https://github.com/zauberzeug/nicegui/tree/main/examples/single_page_app/
only modify the show_two in single page app example main.py like this, and local image will never be loaded

    @router.add('/two')
    def show_two():
        # https://github.com/zauberzeug/nicegui/blob/main/website/static/logo_square.png?raw=true
        ui.image('logo_square.png')
2024-06-15.00-54-27.mp4
@atticus-lv
Copy link
Author

the main.py file is insdie single_page_app. actually I use an absolute path/web image will also have this problem. I will upload a screenshot later

@atticus-lv
Copy link
Author

yes, check this video @python-and-fiction

2024-06-15.16-08-10.mp4
    @router.add('/')
    def show_one():
        ui.image('https://github.com/zauberzeug/nicegui/blob/main/website/static/logo_square.png?raw=true')

    @router.add('/two')
    def show_two():
# my local path
        ui.image(r'C:\Users\atticus\Desktop\ToDoList-nicegui\single_page_app\logo_square.png')

    @router.add('/three')
    def show_three():
# your solution
        ui.image('single_page_app/logo_square.png')

@atticus-lv
Copy link
Author

@falkoschindler hi falkoschindler, do you have any idea on this problem?

@python-and-fiction
Copy link

python-and-fiction commented Jun 15, 2024

same as #2011
Follow this
#2035 (comment)

@atticus-lv
Copy link
Author

add statics file seem not work for me, but adding all reroute with ui.page works

@falkoschindler
Copy link
Contributor

Hi @atticus-lv,

This is very confusing, but I think I understand what is happening:
The @ui.page('/{_:path}') decorator creates an endpoint that matches all routes including static images paths. But since the router can't serve images, the image isn't displayed.

As a workaround, you can limit the route to non-path strings (i.e. strings not containing a slash /): @ui.page('/{_}').

I'll close this issue, because it isn't really a bug but a limitation of our small "single page app" example.
A much more powerful API is in the making: PR #2811.

@falkoschindler falkoschindler closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants