Answer the question
In order to leave comments, you need to log in
"jinja2.exceptions.UndefinedError: 'url_for' is undefined". Where is the problem here?
from flask import Flask, url_for
from flask import render_template
from jinja2 import Environment, FileSystemLoader
app = Flask(__name__)
persons = [
{"name": "Алексей", "old": 18, "weight": 78.5},
{"name": "Николай", "old": 28, "weight": 82.3},
{"name": "Иван", "old": 33, "weight": 94.0}
]
file_loader = FileSystemLoader('templates')
env = Environment(loader=file_loader)
tm = env.get_template('/index.html')
msg = tm.render(persons=persons)
print(msg)
@app.route("/")
def index():
print(url_for('index'))
return render_template('index.html', persons=persons)
if __name__=="__main__":
app.run(debug=True)
<!DOCTYPE html>
<html>
<head>
<link type="text/css" href="{{ url_for('static', filename='css/style.css')}}" rel="stylesheet" />
</head>
<body>
<div class=page>hello</div>
<ul>
{% for u in persons -%}
{{u.name,u.old}}
{% endfor -%}
</ul>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question