0Pricing
Flask Academy · Lektion

Blueprint-spezifische Templates und statische Dateien

Geben Sie jedem Blueprint eigene Assets.

Blueprint-spezifische Templates und statische Dateien ist eine kostenlose Flask Academy-Lektion auf CoddyKit. Dies ist Lektion 4 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.

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

Häufig gestellte Fragen

Ist die Lektion „Blueprint-spezifische Templates und statische Dateien“ kostenlos?

Ja — der vollständige Text von „Blueprint-spezifische Templates und statische Dateien“ 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 „Blueprint-spezifische Templates und statische Dateien“?

Geben Sie jedem Blueprint eigene Assets. 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 4 von 4.

Wie lange dauert die Lektion „Blueprint-spezifische Templates und statische Dateien“?

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