I’m trying to write my first webapp with Flask. I learned that to use css in my site, I have to use a static folder, because my css is never gonna change while the site is running (when it is online). So i created it, wrote a bit of css, imported it in my html via this portion of code
<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='homeStyle.css')}}">
I guess the code is correct, because if I press CTRL + SHIFT + I in my site, in the source part it shows me the correct folder, with the correct file, but it shows me it always empty, so all the css I wrote is not applied in my page. I tryied to save all the document again, refresh the server, even if debug mode is on, and nothing changes. I also tryied with other source code, but it never import it.
I read the documentation: https://flask.palletsprojects.com/en/1.1.x/tutorial/static/
Also this sites:Application not picking up .css file (flask/python)
https://pythonbasics.org/flask-static-files/
They do the same thing that I did, but it don’t works for me. Can someone help me please?
I think the problem is something connected to the reading of css, because all is correctly find, but it can’t open it, never.
Thanks for your time
Advertisement
Answer
All the content you wrote is probably correct. The issue is for sure on synchronization of the files. If you are on windows and you have OneDrive on, maybe it is causing problem with the cloud and the upload. So, try to run the code on a different OS, or on a virtual machine, or try to put off all the cloud upload. I think that is the problem, because I had a similar problem.