Szablony i pliki statyczne przypisane do Blueprintu
Nadaj każdemu Blueprintowi własne zasoby.
Szablony i pliki statyczne przypisane do Blueprintu to bezpłatna lekcja Flask Academy na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Flask Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Flask Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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.cssPortable 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. 🎉
Często zadawane pytania
Czy lekcja „Szablony i pliki statyczne przypisane do Blueprintu” jest bezpłatna?
Tak — pełny tekst „Szablony i pliki statyczne przypisane do Blueprintu” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Flask Academy, przejdź na CoddyKit PRO. Kurs Flask Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Szablony i pliki statyczne przypisane do Blueprintu”?
Nadaj każdemu Blueprintowi własne zasoby. Ćwiczysz Flask Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Flask Academy?
Nie wymagamy żadnego doświadczenia. Flask Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Szablony i pliki statyczne przypisane do Blueprintu”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Flask Academy?
Tak. Każda lekcja Flask Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Dlaczego Blueprinty są lepsze niż jeden wielki plik
- Tworzenie i rejestrowanie Blueprintu
- Prefiksy URL i url_for w Blueprintach
- Szablony i pliki statyczne przypisane do Blueprintu