如何从Blueprint模板扩展基础Flask Jinja模板? [英] How to extend a base Flask Jinja template from a Blueprint template?

查看:209
本文介绍了如何从Blueprint模板扩展基础Flask Jinja模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flask和Jinja创建一个相当大的应用程序。 Flask建议使用蓝图将大型应用程序分成更小的单元。如果我有我的整个应用程序/网站的基础布局,我怎么能从我的蓝图中的模板扩展这个?

只需写出基本模板布局的名称,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆