- for
- in
- endfo
Flask Jinja template with loop
examples/flask/jinja-loop/app.py
from flask import Flask, render_template app = Flask(__name__) @app.route("/") def main(): languages = [ 'English', 'Spanish', 'Hebrew', 'Hungarian', ] return render_template('main.html', title = "Code Maven Jinja example", languages = languages, )
examples/flask/jinja-loop/templates/main.html
<h1>{{ title }}</h1> <ul> {% for lang in languages %} <li>{{ lang }}</li> {% endfor %} </ul>
examples/flask/jinja-loop/test_app.py
import app def test_app(): web = app.app.test_client() rv = web.get('/') assert rv.status == '200 OK' assert b'<h1>Code Maven Jinja example</h1>' in rv.data assert b'<li>Hungarian</li>' in rv.data