How Do We Serve Static Files?
Understand how to serve static assets such as CSS, images, and JavaScript files in Flask. Learn to create a static directory, generate absolute URLs with url_for, and integrate these files into your web templates efficiently.
What are static files?
Static files, or assets, are the files that the server sends to the clients “as-it-is”, i.e., without any intervention. For example, any CSS files, background images, or JavaScript files that we might have on our website are sent to the client without modification.
Steps to Serve Static Files
The following steps need to be taken to host a static asset.
Create a \static directory
First, similar to the templates, we need to create a directory called \static in our project for Flask to ...