Q: I'm trying to use an external CSS file to style my Flask template, but the styles aren't being applied. Here's my file structure:
/app - app_runner.py /services - app.py /templates - mainpage.html /styles - mainpage.css
mainpage.html
<html> <head> <link rel= "stylesheet" type= "text/css" href= "../styles/mainpage.css"> </head> <body> <!-- content -->
A: To resolve this issue, you need to have a dedicated 'static' folder for storing your CSS and JS files. Here's the corrected file structure:
/app - app_runner.py /services - app.py /templates - mainpage.html /static /styles - mainpage.css
mainpage.html
<html> <head> <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/mainpage.css') }}"> </head> <body> <!-- content -->
Flask will now look for the CSS file under static/styles/mainpage.css.
The above is the detailed content of Why Isn\'t My External CSS File Loading in My Flask Application?. For more information, please follow other related articles on the PHP Chinese website!