0Pricing
Flask Academy · Lektion

Einen Blueprint erstellen und registrieren

Definieren Sie einen Blueprint und verbinden Sie ihn mit der App.

Einen Blueprint erstellen und registrieren ist eine kostenlose Flask Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Flask Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Flask Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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. 🎉

Häufig gestellte Fragen

Ist die Lektion „Einen Blueprint erstellen und registrieren“ kostenlos?

Ja — der vollständige Text von „Einen Blueprint erstellen und registrieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Flask Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Flask Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Einen Blueprint erstellen und registrieren“?

Definieren Sie einen Blueprint und verbinden Sie ihn mit der App. Du übst Flask Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Flask Academy zu starten?

Keine Vorkenntnisse erforderlich. Flask Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Einen Blueprint erstellen und registrieren“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Flask Academy-Lektion Code schreiben und ausführen?

Ja. Jede Flask Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Warum Blueprints eine große Datei übertreffen
  2. Einen Blueprint erstellen und registrieren
  3. URL-Präfixe und Blueprint-url_for
  4. Blueprint-spezifische Templates und statische Dateien
← Zurück zu Flask Academy