0PricingLogin
Flask Academy · Lesson

Link Assets with url_for static

Reference CSS and JS without hardcoded paths.

Stop Hardcoding Paths

Writing /static/style.css by hand in every template feels easy, but it is fragile. Flask gives you url_for to build asset links for you. 🔧

The static Endpoint

Flask registers a built-in endpoint named static for your assets. You ask url_for for it instead of typing the raw path yourself.

All lessons in this course

  1. The static Folder Convention
  2. Link Assets with url_for static
  3. Cache Busting with File Versions
  4. Static Files in Production Reality
← Back to Flask Academy