如何从Blueprint模板扩展基础Flask Jinja模板? [英] How to extend a base Flask Jinja template from a Blueprint template?
问题描述
只需写出基本模板布局的名称,Flask就会在应用程序的模板文件夹中找到它,然后在蓝图的模板文件夹中找到。
{%extends'template_name.html'%}
$ b 如果它存在于templates文件夹中,
{%extends'folder_name / template_name.html'%}
$如果在应用程序的模板文件夹和蓝图的模板文件夹中有两个同名的模板,那么应用程序的模板文件夹中的模板将获得优先权。
有关更多信息,请参见此问题烧录蓝图模板文件夹
如果Flask位于右侧,Flask会自动为您找到模板sitions。
I am creating a fairly large application using Flask and Jinja. Flask recommends separating large applications into smaller units using Blueprints. If I have a base layout for my entire application/website, how can I extend this from templates within my blueprints?
解决方案You simply write name of the base template layout and Flask will find it if it exists in app's templates folder and then in blueprint's templates folder.
{% extends 'template_name.html' %}
If it exists inside a folder in templates folder then
{% extends 'folder_name/template_name.html' %}
If there are two templates with same name in app's templates folder and blueprint's template folder, then template in app's templates folder will get priority.
See this question for more info flask blueprint template folder
Flask automatically finds templates for you if they are placed at right positions.
这篇关于如何从Blueprint模板扩展基础Flask Jinja模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!