Hackforge Academy

Category: python

jinja2 templates

Published on 30 Sep 2026

Explanation

Jinja2 is Flask's template engine for generating dynamic HTML pages.

Code:

from flask import render_template

@app.route('/')
def home():
    return render_template('index.html')

Explanation

Python values can be passed from a Flask route to a Jinja2 template.

Code:

@app.route('/profile')
def profile():
    return render_template(
        'profile.html',
        name='Praveen'
    )

Explanation

Jinja2 variables are displayed using double curly braces.

Code:

<h1>Welcome {{ name }}</h1>

Explanation

Jinja2 supports conditional statements for dynamic page rendering.

Code:

{% if user %}
    <h2>Hello {{ user.name }}</h2>
{% else %}
    <h2>Please Login</h2>
{% endif %}

Explanation

Jinja2 supports loops for displaying collections of data.

Code:

<ul>
{% for user in users %}
    <li>{{ user.name }}</li>
{% endfor %}
</ul>

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community