Home >Web Front-end >CSS Tutorial >How Do I Properly Link External CSS Files in My Flask Application?
How to Incorporate CSS Files in Flask Applications
When styling templates in Flask applications using external style sheets, it's crucial to understand the proper file structure. In this context, the provided error message indicates an issue with the application not retrieving the CSS file.
The directory structure should organize files as follows:
/app - app_runner.py /services - app.py /templates - mainpage.html /static /styles - mainpage.css
Ensure that the /styles directory resides within /static.
To specify the style sheet in the template, use the following syntax:
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/mainpage.css') }}">
This path directs Flask to search for the CSS file within the "static/styles/mainpage.css" location.
By adhering to this file structure and template syntax, you can successfully link external CSS files to your Flask application, ensuring proper styling.
The above is the detailed content of How Do I Properly Link External CSS Files in My Flask Application?. For more information, please follow other related articles on the PHP Chinese website!