quasarstatic-contentjustpy

JustPy QuasarPage - where do I put the favicon file in my project tree?


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:

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.

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)


Solution

  • 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.