[Flask] Blueprints templates
Jerry Mccreary
jerry.mccreary at mac.com
Sun Mar 18 14:07:53 EDT 2018
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.
--
> On Mar 18, 2018, at 1:33 PM, Laura Morales <lauretas at mail.com> wrote:
>
> The documentation [1] says to use this structure for blueprint templates:
>
>
> yourpackage/
> blueprints/
> admin/
> templates/
> admin/
> index.html
> __init__.py
>
>
> but it looks like a hack to me. Is there any flag that I can toggle, such that "<blueprint>/index.html" will automatically reference a blueprint without the need to create the additional folder? For example "admin/index.html" will locate the file "yourpackage/blueprints/admin/templates/index.html"
>
>
> [1] http://flask.pocoo.org/docs/0.12/blueprints/#templates
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20180318/48a7cab6/attachment-0001.html>
More information about the Flask
mailing list