简体   繁体   中英

How to extend a base Flask Jinja template from a Blueprint template?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM