#encoding:utf-8
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def index():
books=[
{
'name' :u'红楼梦',
'author':u'曹雪芹',
'price':200
},
{
'name': u'水浒传',
'author': u'施耐庵',
'price': 100
},
{
'name': u'三国演义',
'author': u'罗贯中',
'price': 120
},
{
'name': u'西游记',
'author': u'吴承恩',
'price': 230
}
]
return render_template('item.html',books=books)
if __name__ == '__main__':
app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table>
<thead>
<th>书名</th>
<th>作者</th>
<th>价钱</th>
</thead>
<tbody>
<meta charset="UTF-8">
{% for book in books %}
<tr>
<td>{{ book.name}}</td>
<td>{{ book.author}}</td>
<td>{{ book.price}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
本文介绍了一个简单的Flask应用实例,该应用用于展示一系列中国古典名著的信息,包括书名、作者及价格等,并通过HTML模板进行呈现。

被折叠的 条评论
为什么被折叠?



