NelsonLabs
Flask/Static Files

Static Files

Flask serves static files (CSS, JS, images) from a 'static' folder automatically. In production you'll configure your web server to serve them directly.

Static files setup
python
# Flask serves from a 'static/' directory by default
# static/
#   css/
#     style.css
#   js/
#     app.js
#   images/
#     logo.png

# In templates — use url_for to generate URLs
# <link href="{{ url_for('static', filename='css/style.css') }}" />
# <img src="{{ url_for('static', filename='images/logo.png') }}" />
# <script src="{{ url_for('static', filename='js/app.js') }}"></script>

# Custom static folder
app = Flask(__name__, static_folder="public", static_url_path="/assets")
# Now: /assets/style.css → public/style.css