Dash how use assets for file.css

Hello everyone, I’ve been using Dash for about a week. I really like the idea of using it alongside HTML. However, I’m having serious problems with reading .css files. I’m trying to create a warehouse program that uses a database (datab.db).

For now, I’m not discussing the connections, but rather the simple forms I’m creating to display data in the browser. I find it a bit annoying to have to place the stylesheets in an “assets” folder, as I can’t directly select the most appropriate .css file for one mask or another. It’s frustrating; it probably has its own logic.

What I’ve understood is that if I use 2 .css files, for example, style1.css and style2.css, Dash loads both of them, and depending on the classes it finds, it will apply the css for one mask or the other—this means I have to remember the class names or IDs for each .css file to avoid conflicts.

To prevent overlaps, I thought about creating subfolders within the main folder structured like this:

  • mainFolder/app.py

  • mainFolder/navbar/navbar.py

  • mainFolder/navbar/assets/navbar.css

  • mainFolder/menubar_maschere/menubar_maschere.py

  • mainFolder/menubar_maschere/assets/menubar_maschere.css

  • mainFolder/maschera1/maschera1.py

  • mainFolder/maschera1/assets/maschera1.css

and so on. I might be wrong about my approach, but at least I have my own logic.

Now, I’m having huge difficulties—in all cases—connecting the .css to the app that requires it, and I don’t understand why. In theory, if I run navbar.py, which has its navbar.css in mainFolder/navbar/assets, Dash should receive the stylesheet from the assets and load it automatically, showing it in the browser.

I’ve tried everything: with relative and absolute paths, directly writing the path:

`navbar_css_path = os.path.abspath(‘H:\mainFolder\navbar\assets\navbar.css’)

Check if the CSS file exists

if os.path.exists(navbar_css_path):
print(“CSS file found.”)
else:
print(“Error: The CSS file does not exist.”)`

But even if it finds it, the stylesheet doesn’t load. Why?
Where am I going wrong?