0

Problem statement

I'm trying to set the favicon for my QuasarPages in a JustPy web app, adding the attribute favicon="book_icon_32.png" to my QuasarPage. When looking at the page source in my browser results in the following in the page head:

<link rel="shortcut icon" href=http://127.0.0.1:8080/static/book_icon_32.png>

I get the same result if instead I use

home_page.favicon = "book_icon_32.png"

The problem is that I can't figure out where the image file needs to be placed in the project tree, or if I'm missing some JustPy/Quasar object.

Can someone point me in the right direction?

More details, and some of the things I've tried.....

My project directory (in PyCharm, if that makes a difference) has main.py which contains jp.justpy(port=8080) in the root directory, and all the JustPy webpage classes in <root>/webapp. I've tried putting the file in:

  • <root>/static
  • <root>/webpage/static

and other places/relative URIs, all with the same result (blank page icon). After looking at the Quasar docs on static content, I also tried "public" directories for the image file.

  • <root>/public
  • <root>/webapp/public

and even putting copies of the .png file in the <root> and <webapp> directories. I've also tried looking at http://127.0.0.1:8080/static after all of these attempts, and all I get in the browser is

{"detail":"Not Found"}

And a few other things, all with no luck.

Of course, lots of Googling, searching Stack Overflow, trying to find any bread crumbs in the JustPy and Quasar docs, etc. I've also looked for examples that explicitly show the use of a favicon in other JustPy questions here and of course, I couldn't find any fully-worked examples elsewhere where there's a favicon used.

Time to stop thrashing around and ask for help.

FWIW, from my source:

home_page = jp.QuasarPage(title=AppConstants.APP_TITLE, favicon="book_icon_32.png", tailwind=True)

  • I tried using Chrome instead of Edge, and I get something a little different, not sure why: `// 20230818110707 // http://127.0.0.1:8080/static/ { "detail": "Not Found" } ` – Steve Elkind Aug 18 '23 at 15:08
  • Make that: `// 20230818111522 // http://127.0.0.1:8080/static/book_icon_32.png { "detail": "Not Found" } ` – Steve Elkind Aug 18 '23 at 15:17
  • Something unexpected in many attempts after finding `https://justpy.io/tutorial/static/`. I tried various combos of URLs and file paths. Seemingly by accident found one combo that works - image file in any location under /files. E.g., `favicon="/files/book_icon_32.png"` or `favicon="/files/img/book_icon_32.png"` This does not agree with the tutorial. Other directory names (and relative URLs) than "/files" did not work. In the rendered page source, "static" is still in the URL path `href=http://127.0.0.1:8080/static/files/img/book_icon_32.png`. Still no clue as to a full answer – Steve Elkind Aug 18 '23 at 17:01

1 Answers1

0

I found an answer (of sorts) after finding something in the issues list in the JustPy github. Explicitly defining the static files location lets me avoid whatever the default behavior is for static content.

You can explicitly define the location of static files by using a JustPy config text file (justpy.env) file in the directory where your app is run from (docs, tutorial). My justpy.env file has one line in it:

STATIC_DIRECTORY = "static_content"

I put the .png file into <root>/static_content/images, and then restarted. In the rendered page source, the favicon link becomes:

<link rel="shortcut icon" href=http://127.0.0.1:8080/static/images/book_icon_32.png>

Now the whole thing works. This leads me to believe the default behavior might be the default value for the directory location is <root>/files, but I'm not going to depend on it.