Я впервые использую флягу, делал уроки от youtube.Я перепроверил код, но не решил.Вывод последних кодов, которые находятся в «for», не печатает
Код Python:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World!'
@app.route('/about')
def about():
return 'The About Page'
@app.route('/blog')
def blog():
posts = [{'title': 'Technology in 2019', 'author': 'Sreeram'},
{'title': 'Expansion of oil in Russia', 'author': 'Bob'}]
return render_template('blog.html', author='bob', sunny=True)
@app.route('/blog/<string:blog_id>')
def blogpost(blog_id):
return 'This is blog post number' + (blog_id)
if __name__ == '__main__':
app.debug = True
app.run()
HTML-код:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>blog</title>
</head>
<body>
<h2> Welcome to this blog! </h2>
<p> I am Sreeram, the author of this blog </p>
{% if sunny %} -->
<p> Today it is sunny</p> -->
{% else %} -->
<p> Today it is rainy</p> -->
{% endif %} -->
{% for post in posts %}
<h2>{{post.title}}</h2>
<h3>Author : {{post.author}}</h3>
{% endfor %}
</body>
</html>
Я получаю вывод какэто:
Выход