Menu

Flask: Separate Templates and Static Files per Blueprint — Stop Your templates/ Folder from Ballooning in 5 Minutes
📰

Flask: Separate Templates and Static Files per Blueprint — Stop Your templates/ Folder from Ballooning in 5 Minutes

DEV Community: flask·Linh Fish Dev·about 4 hours ago
#ssyl7v3z
#devtoflask#devto#dev#admin#templates
Long article (898 words) — no AI summary yet.
Reading 0:00
15s threshold

As a Flask app grows, templates and static files piling up in the root-level templates/ and static/ folders quickly turn into a mess: two modules can easily collide on index.html or style.css , and when you move a module to another project, its templates get left behind. The cleanest fix: pass template_folder and static_folder when you create a Blueprint , so each module carries its own templates and static files.

The Problem

Suppose your app has two blueprints — admin and shop — and both need an index.html page. Without separate folders, both files have to live in the same templates/ directory, but only one file can have that name. The usual workaround is long names like admin_index.html and shop_index.html : the more modules you add, the longer the filenames get, and the harder it is to tell which file belongs to which module.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.