Sometimes, we want to include a HTML file in a Jinja2 template with Python Flask.
In this article, we’ll look at how to include a HTML file in a Jinja2 template with Python Flask.
How to include a HTML file in a Jinja2 template with Python Flask?
To include a HTML file in a Jinja2 template with Python Flask, w ecan use the include
directive.
For instance, we write
{% extends 'template.html' %}
{% block content %}
{% if task == 'content1' %}
{% include 'content1.html' %}
{% endif %}
{% if task == 'content2' %}
{% include 'content2.html' %}
{% endif %}
{% endblock %}
in our Jinja template to include the content1.html and content2.html files with
{% include 'content1.html' %}
and
{% include 'content2.html' %}
Conclusion
To include a HTML file in a Jinja2 template with Python Flask, w ecan use the include
directive.
Popular Posts
- Show / Hide div based on dropdown selected using jQuery
- Autosuggestion Select Box using HTML5 Datalist, PHP and MySQL with Example
- Custom Authentication Login And Registration Using Laravel 8
- Infinite Scrolling on PHP website using jQuery and Ajax with example
- Google Login or Sign In with Angular Application
- How to Convert MySQL Data to JSON using PHP
- How to change date format in PHP?
- Image Lazy loading Using Slick Slider
- Slick Slider Basic With Example
- php in_array check for multiple values
- Adaptive Height In Slick Slider
- Slick Slider Center Mode With Example
- How to Scroll to an Element with Vue 3 and ?
- JavaScript Multiple File Upload Progress Bar Using Ajax With PHP
- Slick Slider Multiple Items With Example
Total Views: 857