Is it possible to perform Includes with flask?

42,512

By default, Flask uses Jinja2 as its template engine. See Jinja's Template Designer Documentation how it's done.

Share:
42,512
Michael
Author by

Michael

Updated on July 09, 2022

Comments

  • Michael
    Michael almost 2 years

    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?

  • jOSe
    jOSe over 3 years
    But is it possible to highlight, which page is active in sidenavigation.html?
  • John Crawford
    John Crawford about 2 years
    @jOSe You can make use of the scoped keyword in the block definition within "sidenavigation.html". See Jinja's "Block Nesting and Scope" section. Their example is {% block loop_item scoped %}{{ item }}{% endblock %} which allows item to pull its definition from the inheriting template.