0Pricing
Flask Academy · Lesson

Blueprint-Scoped Templates and Statics

Give each blueprint its own assets.

Blueprint-Scoped Templates and Statics is a free Flask Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Each Feature Owns Its Assets

A truly modular blueprint carries its own templates and static files. This keeps a feature self-contained and easy to move around.

Point to a Template Folder

When you create the blueprint, set template_folder so Flask also searches that folder when rendering this blueprint pages.

blog = Blueprint("blog", __name__,
    template_folder="templates")

Folders Are Relative

That template path is relative to the blueprint module thanks to __name__. Flask resolves it from where the blueprint file lives.

Templates Are Searched, Not Isolated

Flask merges every template folder into one search path. The blueprint folder is added to the global app templates, not fully walled off.

Avoid Template Name Clashes

Because folders merge, two blueprints with the same filename can collide. Namespace templates by nesting them in a per-blueprint subfolder.

render_template("blog/post.html")

Add a Static Folder

A blueprint can ship its own CSS and images too. Set static_folder at creation to hold this feature private assets.

blog = Blueprint("blog", __name__,
    static_folder="static")

Link Blueprint Static Files

Reference those assets with url_for and the namespaced static endpoint, so each blueprint serves its own files cleanly.

url_for("blog.static", filename="blog.css")

Set a Static URL Path

Give the assets a public route with static_url_path. This controls the URL browsers use to fetch the blueprint files.

Blueprint("blog", __name__,
    static_url_path="/blog-static")

App Static Still Exists

The main app keeps its own /static for shared assets. Blueprint statics live alongside it, each reached by its own endpoint.

A Tidy Blueprint Folder

The payoff is a clean package: routes, templates, and static files in one place. That folder is the whole feature, ready to reuse. 📦

blog/
  routes.py
  templates/blog/
  static/blog.css

Portable by Design

Since assets travel with the code, you can copy a blueprint into another project and it still works with little extra setup. 🚀

Quick Check

How do you link a blueprint static file?

Recap

Set template_folder and static_folder on a blueprint so it owns its assets, namespace templates, and link statics via blog.static. 🎉

Frequently asked questions

Is the “Blueprint-Scoped Templates and Statics” lesson free?

Yes — the full text of “Blueprint-Scoped Templates and Statics” is free to read here on the web, and the Flask Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flask Academy course, upgrade to CoddyKit PRO.

What will I learn in “Blueprint-Scoped Templates and Statics”?

Give each blueprint its own assets. You practise Flask Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Flask Academy?

No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Blueprint-Scoped Templates and Statics” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Flask Academy lesson?

Yes. Every Flask Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Why Blueprints Beat One Giant File
  2. Create and Register a Blueprint
  3. URL Prefixes and Blueprint url_for
  4. Blueprint-Scoped Templates and Statics
← Back to Flask Academy