admin管理员组文章数量:1392086
In Flask, I am attempting to nest blueprints but am running into issues with templates folders.
Prior to blueprints nesting, the fix was to duplicate the relative path to the blueprint in its templates folder.
app/bp/a/templates/a/index.html
app/bp/b/templates/b/index.html
This feels less acceptable with nested blueprints. For example, for blueprints:
app/bp/a/
app/bp/a/_id/
app/bp/a/_id/a1/
app/bp/a/_id/a1/_id/
app/bp/b/
app/bp/b/_id/
app/bp/b/_id/a1/
app/bp/b/_id/a1/_id/
Instead of (sorted by nest level, for readability):
app/bp/a/templates/index.html
app/bp/b/templates/index.html
app/bp/a/_id/templates/index.html
app/bp/b/_id/templates/index.html
app/bp/a/_id/a1/templates/index.html
app/bp/b/_id/a1/templates/index.html
app/bp/a/_id/a1/_id/templates/index.html
app/bp/b/_id/a1/_id/templates/index.html
I'd need (sorted by nest level, for readability):
app/bp/a/templates/a/index.html
app/bp/b/templates/b/index.html
app/bp/a/_id/templates/a/_id/index.html
app/bp/b/_id/templates/b/_id/index.html
app/bp/a/_id/a1/templates/a/_id/a1/index.html
app/bp/b/_id/a1/templates/b/_id/a1/index.html
app/bp/a/_id/a1/_id/templates/a/_id/a1/_id/index.html
app/bp/b/_id/a1/_id/templates/b/_id/a1/_id/index.html
At the deeper nested levels, this becomes overly redundant. It also requires manually entering the parent paths recursively into the template folder of every blueprint, making higher-level path name changes a nightmare.
How do I setup these blueprints to be able to:
- Specify the blueprint (or its path) in addition to the template name in
render_template()
. - Skip shadowing the parent path(s) in blueprint templates folders.
Should I just set templates_folder
to absolutePathToAppRoot
for every blueprint and then render_template()
to <relativePathFromAppRoot>/templates/index.html
?
本文标签: Flask Nested blueprints with templates with duplicate namesStack Overflow
版权声明:本文标题:Flask: Nested blueprints with templates with duplicate names - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744781056a2624715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论