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

For some reason I can't get favicon to show in my app #4099

Open
vmlstandard opened this issue Dec 14, 2024 · 2 comments
Open

For some reason I can't get favicon to show in my app #4099

vmlstandard opened this issue Dec 14, 2024 · 2 comments

Comments

@vmlstandard
Copy link

vmlstandard commented Dec 14, 2024

Description

This code demonstrates the problem with favicon:

from nicegui import app, ui

favicon_name = "favicon3.ico"
app.add_static_files('/static', 'static')

@ui.page('/', favicon='static/' + favicon_name)
def index_page() -> None:
    # ui.html("<link rel='icon' type='image/x-icon' href='static/" + favicon_name + "'>")
    ui.avatar('img:/static/' + favicon_name, color='white', square=False)

ui.run(title='FavIcon Demo', favicon='static/' + favicon_name)

static.zip

It only works with the ui.html(...) line un-commented.
The @ui.page and ui.run seem to ignore the favicon

I have added several favicon files I have tried, in case these could be the issue.

I'm probably missing something...

Please help solving this mystery,

Thank you

@rodja
Copy link
Member

rodja commented Dec 15, 2024

Are you absolutely sure that there is a static folder containing your favicon in the working directory?

Btw: this is the code which determines the favicon url

def get_favicon_url(page: page, prefix: str) -> str:
"""Return the URL of the favicon for a given page."""
favicon = page.favicon or core.app.config.favicon
if not favicon:
return f'{prefix}/_nicegui/{__version__}/static/favicon.ico'
favicon = str(favicon).strip()
if _is_remote_url(favicon):
return favicon
if _is_data_url(favicon):
return favicon
if _is_svg(favicon):
return _svg_to_data_url(favicon)
if _is_char(favicon):
return _svg_to_data_url(_char_to_svg(favicon))
if page.path == '/' or page.favicon is None:
return f'{prefix}/favicon.ico'
return f'{prefix}{page.path}/favicon.ico'

So you either need to provide the full remote url or use the file location.

@jixian01
Copy link

jixian01 commented Jan 2, 2025

Hey Happy new year guys,
I am facing the similar issue.
nicegui: 2.9.0
python: 3.12.8

my test is env is very simple

  • Project folder
    -- main.py
    -- rocketicon.png

in main.py, try to use the rocketicon.png file as favicon
ui.run(favicon='rocketicon.png', uvicorn_logging_level="debug")
but the result html still keep

what wrong with my env or code? thank you

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