[Flask] Blueprints templates

Laura Morales lauretas at mail.com
Sun Mar 18 14:29:47 EDT 2018


Yes I'd like to divide my websites into 2 modules (blueprints), developed by two separate groups. So, each blueprint will contain its own templates, views, static assets etc.
Right now I use "module-1/templates/module-1/template.html" but it looks a bit hackish. I was hoping there was a way to remove the need of the inner "module-1" folder, and have Flask instead automatically recognize that "module-1/template.html" is actually "template.html" inside "module-1/templates/".

> the blueprint using templates_folder attribute.
> By using this parameter, you point to the blueprint’s template directory
> once, and the associated views will look in that directory.

Does this solve the problem with different blueprints having a template with the same name?
 
 

Sent: Sunday, March 18, 2018 at 7:07 PM
From: "Jerry Mccreary" <jerry.mccreary at mac.com>
To: "Laura Morales" <lauretas at mail.com>
Cc: flask at python.org
Subject: Re: [Flask] Blueprints templates

I’m not sure if this answers your question:
 
The structure you reference is for project and maintenance organization, keeping blueprint assets together.
Blueprints can also go in the main templates folder at root of project.
 
Ex:
yourpackage/
blueprints/
admin/
__init__.py
models.py
views.py
 
templates/  (main templates folder)
admin/
index.html
blueprint2/
index.html 
blueprint3/
index.html

 
The subfolders are used because blueprints may have templates named the same.
For example, if all the templates were in a single directory, they would need to be name without conflict.
 
yourpackage/
blueprints/
etc.
 
templates/ (main templates folder)
admin_index.html
blueprint1_index.html
blueprint2_index.html
blueprint3_index.html
 
Also, when defining the a blueprint, the corresponding template can be defined when declaring the blueprint using templates_folder attribute.
By using this parameter, you point to the blueprint’s template directory once, and the associated views will look in that directory.


More information about the Flask mailing list