Kyle Johnson
Kyle Johnson

Reputation: 1675

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?

Upvotes: 16

Views: 12276

Answers (1)

codecool
codecool

Reputation: 6036

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.

Upvotes: 26

Related Questions