Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to perform Includes with flask?

Say I have a template layout saved in template.html. This template includes a banner, side navigation, content container, and footer. Can I use flask to break up these page elements in such a way that I can have files such as banner.html, sidenavigation.html, etc. and render these different files within template.html?

like image 957
Michael Avatar asked Mar 13 '12 05:03

Michael


People also ask

Does Flask include Jinja?

By default, Flask uses Jinja2 as its template engine.

How do I render a template in Flask?

Make sure you have activated your environment and have Flask installed, and then you can start building your application. The first step is to display a message that greets visitors on the index page. You'll use Flask's render_template() helper function to serve an HTML template as the response.

How do you add separate templates to a different page in Flask?

Simply store all your main code, back end code in app.py. Then all the layout arrangement, template code is in templates. Then inside the templates folder store the html files.


1 Answers

From: http://jinja.pocoo.org/docs/templates/#include

template.html

{% include 'banner.html' %} {% include 'sidenavigation.html' %} {% include 'content.html' %} {% include 'footer.html' %} 
like image 182
Liyan Chang Avatar answered Sep 30 '22 16:09

Liyan Chang