0Pricing
Flask Academy · Lesson

Create and Register a Blueprint

Define a Blueprint and attach it to the app.

Create and Register a Blueprint is a free Flask Academy lesson on CoddyKit — lesson 2 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.

Two Steps to a Blueprint

Working with a blueprint is two moves: first you define it in its own module, then you register it on the app. Let us walk through both.

Import the Blueprint Class

Everything starts with one import. The Blueprint class comes straight from flask, just like the Flask app object does.

from flask import Blueprint

Create the Blueprint Object

You build a blueprint by giving it a name and import_name. The name uniquely identifies this blueprint inside your whole app.

blog = Blueprint("blog", __name__)

What __name__ Does

That second argument, __name__, tells the blueprint where it lives so Flask can later find its templates and static files.

Routes on the Blueprint

Inside the module you attach views with @blog.route instead of @app.route. Same idea, but bound to the blueprint.

@blog.route("/posts")
def posts():
    return "All posts"

Still Dormant for Now

Defining routes is not enough. Until you register the blueprint, none of its URLs respond. The blueprint is inert on its own.

Import It in the App

Over in your app setup, you import the blueprint object from its module so the app can take ownership of it.

from blog.routes import blog

Register on the App

One call wires everything up. register_blueprint copies the blueprint routes onto the app and makes them live.

app.register_blueprint(blog)

Order of Operations

Create the app, import the blueprint, then register it. Get this sequence right and your feature routes spring to life. ✅

Endpoint Names Get Namespaced

A view named posts inside the blog blueprint is referenced as blog.posts. The blueprint name becomes a tidy prefix for endpoints.

Avoiding Circular Imports

Keep the blueprint in its own file and import it where you build the app. This structure sidesteps painful circular import errors.

Quick Check

Which call actually makes a blueprint active?

Recap

Define a Blueprint with a name and __name__, add routes with @bp.route, then call register_blueprint on the app to make them live. 🎉

Frequently asked questions

Is the “Create and Register a Blueprint” lesson free?

Yes — the full text of “Create and Register a Blueprint” 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 “Create and Register a Blueprint”?

Define a Blueprint and attach it to the app. 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 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Create and Register a Blueprint” 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